Class: Bogy::FileHandler

Inherits:
Handler show all
Includes:
Writeable
Defined in:
lib/bogy/handlers/file_handler.rb

Instance Method Summary collapse

Methods inherited from Handler

#hash

Constructor Details

#initialize(path) ⇒ FileHandler

Returns a new instance of FileHandler.

Raises:

  • (ArgumentError)


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

#loadObject



13
14
15
# File 'lib/bogy/handlers/file_handler.rb', line 13

def load
  YAML.load_file(@path)
end

#writeObject



17
18
19
# File 'lib/bogy/handlers/file_handler.rb', line 17

def write
  IO.write(@path, hash.to_yaml)
end