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]
12 13 14 15 16 |
# File 'lib/eac_config/old_configs/file.rb', line 12 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.
9 10 11 |
# File 'lib/eac_config/old_configs/file.rb', line 9 def @options end |
#path ⇒ Object (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
32 33 34 |
# File 'lib/eac_config/old_configs/file.rb', line 32 def autosave? [:autosave] ? true : false end |
#load ⇒ Object
23 24 25 |
# File 'lib/eac_config/old_configs/file.rb', line 23 def load replace(raw_data_from_file) end |
#save ⇒ Object
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 |