Class: Miasma::Models::Storage::File::Streamable
- Inherits:
-
Object
- Object
- Miasma::Models::Storage::File::Streamable
- Defined in:
- lib/miasma/models/storage/file.rb
Overview
Simple wrapper to keep consistent reading behavior
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
IO-ish thing.
Instance Method Summary collapse
-
#initialize(io_item) ⇒ Streamable
constructor
A new instance of Streamable.
-
#method_missing(method_name, *args, &block) ⇒ Object
Proxy missing methods to io.
-
#readpartial(length = nil) ⇒ String
Customized readpartial to automatically hand EOF.
Constructor Details
#initialize(io_item) ⇒ Streamable
Returns a new instance of Streamable.
17 18 19 20 21 22 |
# File 'lib/miasma/models/storage/file.rb', line 17 def initialize(io_item) unless io_item.respond_to?(:readpartial) raise TypeError.new "Instance must respond to `#readpartial`" end @io = io_item end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Proxy missing methods to io
25 26 27 28 29 30 31 |
# File 'lib/miasma/models/storage/file.rb', line 25 def method_missing(method_name, *args, &block) if io.respond_to?(method_name) io.send(method_name, *args, &block) else raise end end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns IO-ish thing.
15 16 17 |
# File 'lib/miasma/models/storage/file.rb', line 15 def io @io end |
Instance Method Details
#readpartial(length = nil) ⇒ String
Customized readpartial to automatically hand EOF
37 38 39 40 41 42 43 |
# File 'lib/miasma/models/storage/file.rb', line 37 def readpartial(length = nil) begin io.readpartial(length) rescue EOFError nil end end |