Class: EacConfig::OldConfigs::File

Inherits:
Base
  • Object
show all
Defined in:
lib/eac_config/old_configs/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#[], #[]=, #clear, #read, #replace

Constructor Details

#initialize(path, options = {}) ⇒ File

Valid options: [:autosave]



12
13
14
15
16
# File 'lib/eac_config/old_configs/file.rb', line 12

def initialize(path, options = {})
  @path = path
  @options = options.to_sym_keys_hash.freeze
  super(raw_data_from_file)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/eac_config/old_configs/file.rb', line 9

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/eac_config/old_configs/file.rb', line 9

def path
  @path
end

Instance Method Details

#autosave?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/eac_config/old_configs/file.rb', line 32

def autosave?
  options[:autosave] ? true : false
end

#loadObject



23
24
25
# File 'lib/eac_config/old_configs/file.rb', line 23

def load
  replace(raw_data_from_file)
end

#saveObject



18
19
20
21
# File 'lib/eac_config/old_configs/file.rb', line 18

def save
  ::FileUtils.mkdir_p(::File.dirname(path))
  ::File.write(path, data.to_h.to_yaml)
end

#write(entry_key, entry_value) ⇒ Object



27
28
29
30
# File 'lib/eac_config/old_configs/file.rb', line 27

def write(entry_key, entry_value)
  super
  save if autosave?
end