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
- #node_attributes=(hash) ⇒ Object
- #reload ⇒ Object
- #save ⇒ Object
- #to_yaml ⇒ Object
Class Method Details
.from_file(file_path) ⇒ Object
38 39 40 |
# File 'lib/soloist/royal_crown.rb', line 38 def self.from_file(file_path) new(read_config(file_path).merge("path" => file_path)) end |
.read_config(yaml_file) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/soloist/royal_crown.rb', line 42 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
17 18 19 |
# File 'lib/soloist/royal_crown.rb', line 17 def env_variable_switches=(hash) self["env_variable_switches"] = Hashie::Mash.new(hash) 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
34 35 36 |
# File 'lib/soloist/royal_crown.rb', line 34 def reload self.class.from_file(path) end |
#save ⇒ Object
28 29 30 31 32 |
# File 'lib/soloist/royal_crown.rb', line 28 def save return self unless path File.open(path, "w+") { |file| file.write(YAML.dump(to_yaml)) } self end |
#to_yaml ⇒ Object
21 22 23 24 25 26 |
# File 'lib/soloist/royal_crown.rb', line 21 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 |