Class: Ez::Settings::Backend::FileSystem

Inherits:
Object
  • Object
show all
Defined in:
lib/ez/settings/backend/file_system.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ FileSystem

Returns a new instance of FileSystem.



9
10
11
# File 'lib/ez/settings/backend/file_system.rb', line 9

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



7
8
9
# File 'lib/ez/settings/backend/file_system.rb', line 7

def file
  @file
end

Instance Method Details

#readObject



13
14
15
16
17
# File 'lib/ez/settings/backend/file_system.rb', line 13

def read
  return {} unless File.exist?(file)

  YAML.load_file(file).deep_symbolize_keys
end

#write(data) ⇒ Object



19
20
21
# File 'lib/ez/settings/backend/file_system.rb', line 19

def write(data)
  File.write(file, read.merge(data).deep_stringify_keys.to_yaml)
end