class ForemanMaintain::YamlStorage
Attributes
data[R]
sub_key[R]
Public Class Methods
load(sub_key)
click to toggle source
# File lib/foreman_maintain/yaml_storage.rb, line 39 def load(sub_key) storage_register[sub_key] ||= load_file.fetch(sub_key, {}) YamlStorage.new(sub_key, storage_register[sub_key]) end
load_file()
click to toggle source
# File lib/foreman_maintain/yaml_storage.rb, line 23 def load_file if File.exist?(storage_file_path) YAML.load_file(storage_file_path) || {} else {} end end
new(sub_key, data = {})
click to toggle source
# File lib/foreman_maintain/yaml_storage.rb, line 8 def initialize(sub_key, data = {}) @sub_key = sub_key @data = data end
save_all()
click to toggle source
# File lib/foreman_maintain/yaml_storage.rb, line 49 def save_all storage_register.each_value(&:save) end
save_sub_key(sub_key, data_val)
click to toggle source
# File lib/foreman_maintain/yaml_storage.rb, line 44 def save_sub_key(sub_key, data_val) new_data = load_file.merge(sub_key => data_val) File.open(storage_file_path, 'w') { |f| f.write new_data.to_yaml } end
storage_file_path()
click to toggle source
# File lib/foreman_maintain/yaml_storage.rb, line 31 def storage_file_path File.expand_path(ForemanMaintain.config.storage_file) end
storage_register()
click to toggle source
# File lib/foreman_maintain/yaml_storage.rb, line 35 def storage_register @storage_register ||= {} end
Public Instance Methods
save()
click to toggle source
# File lib/foreman_maintain/yaml_storage.rb, line 13 def save self.class.save_sub_key(sub_key, data) end
update_and_save(attributes)
click to toggle source
# File lib/foreman_maintain/yaml_storage.rb, line 17 def update_and_save(attributes) @data.merge!(attributes) save end