Class: Rozi::FileWrapperBase
- Inherits:
-
Object
- Object
- Rozi::FileWrapperBase
- Defined in:
- lib/rozi/file_wrapper_base.rb
Overview
Base class for classes that wrap file objects
Direct Known Subclasses
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
Class Method Summary collapse
-
.open(file_path, mode = "r") ⇒ Object
Behaves like File#open, but returns/yields a WaypointFile object.
Instance Method Summary collapse
- #close ⇒ nil
- #closed? ⇒ Boolean
-
#initialize(file) ⇒ FileWrapperBase
constructor
A new instance of FileWrapperBase.
- #rewind ⇒ nil
Constructor Details
#initialize(file) ⇒ FileWrapperBase
Returns a new instance of FileWrapperBase.
27 28 29 |
# File 'lib/rozi/file_wrapper_base.rb', line 27 def initialize(file) @file = file end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
7 8 9 |
# File 'lib/rozi/file_wrapper_base.rb', line 7 def file @file end |
Class Method Details
.open(file_path, mode = "r") ⇒ Object
Behaves like File#open, but returns/yields a WaypointFile object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rozi/file_wrapper_base.rb', line 12 def self.open(file_path, mode="r") file = Rozi.open_file(file_path, mode) wrapper = self.new(file) if block_given? begin return yield wrapper ensure wrapper.close unless wrapper.closed? end else return wrapper end end |
Instance Method Details
#close ⇒ nil
34 35 36 |
# File 'lib/rozi/file_wrapper_base.rb', line 34 def close @file.close end |
#closed? ⇒ Boolean
41 42 43 |
# File 'lib/rozi/file_wrapper_base.rb', line 41 def closed? @file.closed? end |
#rewind ⇒ nil
48 49 50 |
# File 'lib/rozi/file_wrapper_base.rb', line 48 def rewind @file.rewind end |