Class: EacConfig::OldConfigs::File
- Defined in:
- lib/eac_config/old_configs/file.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #autosave? ⇒ Boolean
-
#initialize(path, options = {}) ⇒ File
constructor
Valid options: [:autosave].
- #load ⇒ Object
- #save ⇒ Object
- #write(entry_key, entry_value) ⇒ Object
Methods inherited from Base
#[], #[]=, #clear, #read, #replace
Constructor Details
#initialize(path, options = {}) ⇒ File
Valid options: [:autosave]
11 12 13 14 15 |
# File 'lib/eac_config/old_configs/file.rb', line 11 def initialize(path, = {}) @path = path @options = .to_sym_keys_hash.freeze super(raw_data_from_file) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/eac_config/old_configs/file.rb', line 8 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/eac_config/old_configs/file.rb', line 8 def path @path end |
Instance Method Details
#autosave? ⇒ Boolean
31 32 33 |
# File 'lib/eac_config/old_configs/file.rb', line 31 def autosave? [:autosave] ? true : false end |
#load ⇒ Object
22 23 24 |
# File 'lib/eac_config/old_configs/file.rb', line 22 def load replace(raw_data_from_file) end |
#save ⇒ Object
17 18 19 20 |
# File 'lib/eac_config/old_configs/file.rb', line 17 def save ::FileUtils.mkdir_p(::File.dirname(path)) ::File.write(path, data.to_h.to_yaml) end |
#write(entry_key, entry_value) ⇒ Object
26 27 28 29 |
# File 'lib/eac_config/old_configs/file.rb', line 26 def write(entry_key, entry_value) super save if autosave? end |