Class: EacRubyUtils::Configs
Constant Summary
Constants included
from SimpleCache
SimpleCache::UNCACHED_METHOD_PATTERN
Instance Attribute Summary collapse
Instance Method Summary
collapse
#method_missing, #reset_cache, #respond_to_missing?
Constructor Details
#initialize(configs_key, options = {}) ⇒ Configs
Valid options: [:storage_path]
16
17
18
19
20
|
# File 'lib/eac_ruby_utils/configs.rb', line 16
def initialize(configs_key, options = {})
@configs_key = configs_key
@options = options.to_sym_keys_hash.freeze
load
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class EacRubyUtils::SimpleCache
Instance Attribute Details
#configs_key ⇒ Object
Returns the value of attribute configs_key.
13
14
15
|
# File 'lib/eac_ruby_utils/configs.rb', line 13
def configs_key
@configs_key
end
|
Returns the value of attribute options.
13
14
15
|
# File 'lib/eac_ruby_utils/configs.rb', line 13
def options
@options
end
|
Instance Method Details
#[](entry_key) ⇒ Object
39
40
41
|
# File 'lib/eac_ruby_utils/configs.rb', line 39
def [](entry_key)
read_entry(entry_key)
end
|
#[]=(entry_key, entry_value) ⇒ Object
30
31
32
|
# File 'lib/eac_ruby_utils/configs.rb', line 30
def []=(entry_key, entry_value)
write_entry(entry_key, entry_value)
end
|
#autosave? ⇒ Boolean
47
48
49
|
# File 'lib/eac_ruby_utils/configs.rb', line 47
def autosave?
options[:autosave] ? true : false
end
|
26
27
28
|
# File 'lib/eac_ruby_utils/configs.rb', line 26
def load
self.data = ::EacRubyUtils::PathsHash.new(YAML.load_file(storage_path))
end
|
#read_entry(entry_key) ⇒ Object
43
44
45
|
# File 'lib/eac_ruby_utils/configs.rb', line 43
def read_entry(entry_key)
data[entry_key]
end
|
22
23
24
|
# File 'lib/eac_ruby_utils/configs.rb', line 22
def save
::File.write(storage_path, data.to_h.to_yaml)
end
|
#write_entry(entry_key, entry_value) ⇒ Object
34
35
36
37
|
# File 'lib/eac_ruby_utils/configs.rb', line 34
def write_entry(entry_key, entry_value)
data[entry_key] = entry_value
save if autosave?
end
|