Class: Webgen::Path::SourceIO

Inherits:
Object
  • Object
show all
Defined in:
lib/webgen/path.rb

Overview

Helper class for easy access to the content of a path.

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ SourceIO

Create a new SourceIO object. A block has to be specified that returns an IO object.

Raises:

  • (ArgumentError)


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

#dataObject

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

#streamObject

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