class Masterbaker::RoyalCrown
Public Class Methods
from_file(file_path)
click to toggle source
# File lib/masterbaker/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)
click to toggle source
# File lib/masterbaker/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
Private Class Methods
nilable_properties()
click to toggle source
# File lib/masterbaker/royal_crown.rb, line 69 def self.nilable_properties (properties - [:path]).map(&:to_s) end
Public Instance Methods
env_variable_switches=(hash)
click to toggle source
# File lib/masterbaker/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)
click to toggle source
# File lib/masterbaker/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 = [])
click to toggle source
# File lib/masterbaker/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 = [])
click to toggle source
# File lib/masterbaker/royal_crown.rb, line 25 def merge_recipes(new_recipes = []) merge_array_property("recipes", new_recipes) end
node_attributes=(hash)
click to toggle source
# File lib/masterbaker/royal_crown.rb, line 13 def node_attributes=(hash) self["node_attributes"] = Hashie::Mash.new(hash) end
reload()
click to toggle source
# File lib/masterbaker/royal_crown.rb, line 51 def reload self.class.from_file(path) end
save()
click to toggle source
# File lib/masterbaker/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()
click to toggle source
# File lib/masterbaker/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
Private Instance Methods
merge_array_property(property_name, values)
click to toggle source
# File lib/masterbaker/royal_crown.rb, line 73 def merge_array_property(property_name, values) self[property_name] ||= [] self[property_name] += values self[property_name].uniq! end