Helper class for easy access to the content of a path.
This class is used sothat the creation of the real IO object for # can be delayed till it is actually needed. This is done by not directly requiring the user of this class to supply the IO object, but by requiring a block that creates the real IO object.
Create a new SourceIO object. A block has to be specified that returns the to-be-wrapped IO object.
# File lib/webgen/path.rb, line 46 46: def initialize(&block) 47: @block = block 48: raise ArgumentError, 'You need to provide a block which returns an IO object' if @block.nil? 49: end
Return the whole content of the wrapped IO object as string. For a description of the parameter mode see #.
# File lib/webgen/path.rb, line 66 66: def data(mode = 'r') 67: stream(mode) {|io| io.read} 68: end
Provide direct access to the wrapped IO object by yielding it. After the method block returns the IO object is automatically closed.
The parameter mode specifies the mode in which the wrapped IO object should be opened. This can be used, for example, to open a file in binary mode (or specify a certain input encoding under Ruby 1.9).
# File lib/webgen/path.rb, line 57 57: def stream(mode = 'r') 58: io = @block.call(mode) 59: yield(io) 60: ensure 61: io.close 62: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.