Class: Soloist::RoyalCrown
- Inherits:
-
Hashie::Trash
- Object
- Hashie::Trash
- Soloist::RoyalCrown
- Defined in:
- lib/soloist/royal_crown.rb
Class Method Summary collapse
Instance Method Summary collapse
- #env_variable_switches=(hash) ⇒ Object
- #merge!(other_royal_crown) ⇒ Object
- #merge_cookbook_paths(new_cookbook_paths = []) ⇒ Object
- #merge_recipes(new_recipes = []) ⇒ Object
- #node_attributes=(hash) ⇒ Object
- #reload ⇒ Object
- #save ⇒ Object
- #to_yaml ⇒ Object
Class Method Details
.from_file(file_path) ⇒ Object
55 56 57 |
# File 'lib/soloist/royal_crown.rb', line 55 def self.from_file(file_path) new(read_config(file_path).merge("path" => file_path)) end |
.read_config(yaml_file) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/soloist/royal_crown.rb', line 59 def self.read_config(yaml_file) content = File.read(yaml_file) YAML.load(ERB.new(content).result).tap do |hash| nilable_properties.each do |key| hash.delete(key) if hash[key].nil? end if hash end || {} end |
Instance Method Details
#env_variable_switches=(hash) ⇒ Object
33 34 35 36 |
# File 'lib/soloist/royal_crown.rb', line 33 def env_variable_switches=(hash) self["env_variable_switches"] ||= Hashie::Mash.new self["env_variable_switches"].merge!(Hashie::Mash.new(hash)) end |
#merge!(other_royal_crown) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/soloist/royal_crown.rb', line 17 def merge!(other_royal_crown) merge_recipes(other_royal_crown["recipes"]) merge_cookbook_paths(other_royal_crown["cookbook_paths"]) self.node_attributes.deep_merge!(other_royal_crown["node_attributes"]) self.env_variable_switches = other_royal_crown["env_variable_switches"] self end |
#merge_cookbook_paths(new_cookbook_paths = []) ⇒ Object
29 30 31 |
# File 'lib/soloist/royal_crown.rb', line 29 def merge_cookbook_paths(new_cookbook_paths = []) merge_array_property("cookbook_paths", new_cookbook_paths) end |
#merge_recipes(new_recipes = []) ⇒ Object
25 26 27 |
# File 'lib/soloist/royal_crown.rb', line 25 def merge_recipes(new_recipes = []) merge_array_property("recipes", new_recipes) end |
#node_attributes=(hash) ⇒ Object
13 14 15 |
# File 'lib/soloist/royal_crown.rb', line 13 def node_attributes=(hash) self["node_attributes"] = Hashie::Mash.new(hash) end |
#reload ⇒ Object
51 52 53 |
# File 'lib/soloist/royal_crown.rb', line 51 def reload self.class.from_file(path) end |
#save ⇒ Object
45 46 47 48 49 |
# File 'lib/soloist/royal_crown.rb', line 45 def save return self unless path File.open(path, "w+") { |file| file.write(YAML.dump(to_yaml)) } self end |
#to_yaml ⇒ Object
38 39 40 41 42 43 |
# File 'lib/soloist/royal_crown.rb', line 38 def to_yaml to_hash.tap do |hash| hash.delete("path") self.class.nilable_properties.each { |k| hash[k] = nil if hash[k].empty? } end end |