Class: CloudDoor::CloudYaml
- Inherits:
-
Object
- Object
- CloudDoor::CloudYaml
- Defined in:
- lib/cloud_door/cloud_yaml.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#items ⇒ Object
Returns the value of attribute items.
-
#storage ⇒ Object
Returns the value of attribute storage.
Instance Method Summary collapse
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
5 6 7 |
# File 'lib/cloud_door/cloud_yaml.rb', line 5 def file @file end |
#items ⇒ Object
Returns the value of attribute items.
5 6 7 |
# File 'lib/cloud_door/cloud_yaml.rb', line 5 def items @items end |
#storage ⇒ Object
Returns the value of attribute storage.
5 6 7 |
# File 'lib/cloud_door/cloud_yaml.rb', line 5 def storage @storage end |
Instance Method Details
#load_yaml ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/cloud_door/cloud_yaml.rb', line 7 def load_yaml return false unless File.exist?(@file) all_config = YAML.load_file(@file) return false unless all_config.is_a?(Hash) return false unless all_config.key?(@storage) config = all_config[@storage] @items.each do |item| instance_variable_set("@#{item}", config[item]) if config.key?(item) end true end |
#update_yaml(update_params) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cloud_door/cloud_yaml.rb', line 19 def update_yaml(update_params) if File.exist?(@file) all_config = YAML.load_file(@file) if all_config.key?(@storage) config = all_config[@storage] else config = {} end else all_config = {} config = {} end @items.each do |item| next unless update_params.key?(item) config[item] = update_params[item] end begin all_config[@storage] = config open(@file, 'wb') { |f| YAML.dump(all_config, f) } load_yaml true rescue false end end |