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.
19 20 21 22 |
# File 'lib/webgen/path.rb', line 19 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.
33 34 35 |
# File 'lib/webgen/path.rb', line 33 def data stream {|io| io.read} end |
#stream ⇒ Object
Provide direct access to the wrapped IO object.
25 26 27 28 29 30 |
# File 'lib/webgen/path.rb', line 25 def stream io = @block.call yield(io) ensure io.close end |