Class: Bogy::FileHandler
- Includes:
- Writeable
- Defined in:
- lib/bogy/handlers/file_handler.rb
Instance Method Summary collapse
-
#initialize(path) ⇒ FileHandler
constructor
A new instance of FileHandler.
- #load ⇒ Object
- #write ⇒ Object
Methods inherited from Handler
Constructor Details
#initialize(path) ⇒ FileHandler
Returns a new instance of FileHandler.
6 7 8 9 10 11 |
# File 'lib/bogy/handlers/file_handler.rb', line 6 def initialize(path) raise ArgumentError, "value should be of String type, not #{path.class}" unless path.is_a? String raise IOError, "No such file - #{path}" unless File.exist?(path) @path = path end |
Instance Method Details
#load ⇒ Object
13 14 15 |
# File 'lib/bogy/handlers/file_handler.rb', line 13 def load YAML.load_file(@path) end |
#write ⇒ Object
17 18 19 |
# File 'lib/bogy/handlers/file_handler.rb', line 17 def write IO.write(@path, hash.to_yaml) end |