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.



11
12
13
# File 'lib/ez/settings/backend/file_system.rb', line 11

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



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

def file
  @file
end

Instance Method Details

#readObject



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

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

  YAML.load_file(file).deep_symbolize_keys
end

#write(data) ⇒ Object



21
22
23
# File 'lib/ez/settings/backend/file_system.rb', line 21

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