Class: Hue::Config::Abstract
- Inherits:
-
Object
- Object
- Hue::Config::Abstract
- Defined in:
- lib/hue/config/abstract.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #==(rhs) ⇒ Object
- #delete ⇒ Object
-
#initialize(name, path) ⇒ Abstract
constructor
A new instance of Abstract.
- #write(overwrite_existing_key = false) ⇒ Object
Constructor Details
#initialize(name, path) ⇒ Abstract
Returns a new instance of Abstract.
13 14 15 16 17 |
# File 'lib/hue/config/abstract.rb', line 13 def initialize(name, path) @path = path @name = name self.class.setup_file_path(self.path) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/hue/config/abstract.rb', line 11 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/hue/config/abstract.rb', line 11 def path @path end |
Instance Method Details
#==(rhs) ⇒ Object
41 42 43 44 45 |
# File 'lib/hue/config/abstract.rb', line 41 def ==(rhs) lhs = self lhs.class == rhs.class && lhs.name == rhs.name end |
#delete ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/hue/config/abstract.rb', line 31 def delete yaml = YAML.load_file(self.path) rescue Hash::New if yaml.key?(name) yaml.delete(name) end dump_yaml(yaml) end |
#write(overwrite_existing_key = false) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hue/config/abstract.rb', line 19 def write(overwrite_existing_key = false) yaml = YAML.load_file(self.path) rescue nil yaml ||= Hash.new if yaml.key?(name) && !overwrite_existing_key raise "Key named '#{name}' already exists in config file '#{self.path}'.\nPlease remove it before creating a new one with the same name." else add_self_to_yaml(yaml) dump_yaml(yaml) end end |