Class: Webgen::Path::SourceIO
- Inherits:
-
Object
- Object
- Webgen::Path::SourceIO
- Defined in:
- lib/webgen/path.rb
Overview
Helper class for easy access to the content of a path.
Instance Method Summary collapse
-
#data ⇒ Object
Return the content of the wrapped IO object as string.
-
#initialize(&block) ⇒ SourceIO
constructor
Create a new SourceIO object.
-
#stream ⇒ Object
Provide direct access to the wrapped IO object.
Constructor Details
#initialize(&block) ⇒ SourceIO
Create a new SourceIO object. A block has to be specified that returns an IO object.
17 18 19 20 |
# File 'lib/webgen/path.rb', line 17 def initialize(&block) @block = block raise ArgumentError, 'Need to provide a block which returns an IO object' if @block.nil? end |
Instance Method Details
#data ⇒ Object
Return the content of the wrapped IO object as string.
31 32 33 |
# File 'lib/webgen/path.rb', line 31 def data stream {|io| io.read} end |
#stream ⇒ Object
Provide direct access to the wrapped IO object.
23 24 25 26 27 28 |
# File 'lib/webgen/path.rb', line 23 def stream io = @block.call yield(io) ensure io.close end |