Class: Conjuror::Settings
- Inherits:
-
Object
- Object
- Conjuror::Settings
- Includes:
- Singleton
- Defined in:
- lib/conjuror/settings.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#file ⇒ Object
Returns the value of attribute file.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](key) ⇒ Object
def reload self.use @name, @file end.
-
#[]=(key, value) ⇒ Object
ensures that every new setting is first persisted to the file.
- #directory ⇒ Object
- #method_missing(*args) ⇒ Object
- #path ⇒ Object
-
#use(name = nil, file = nil) ⇒ Object
Returns an instance of the class itself.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
45 46 47 48 49 |
# File 'lib/conjuror/settings.rb', line 45 def method_missing *args return @data[args.first.to_s] if @data && config_defined?(args.first.to_s) return @data[args.first.to_sym] if @data && config_defined?(args.first.to_sym) raise NoMethodError, "Found no such method." end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/conjuror/settings.rb', line 6 def data @data end |
#file ⇒ Object
Returns the value of attribute file.
6 7 8 |
# File 'lib/conjuror/settings.rb', line 6 def file @file end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/conjuror/settings.rb', line 6 def name @name end |
Class Method Details
.directory_for(name) ⇒ Object
51 52 53 |
# File 'lib/conjuror/settings.rb', line 51 def self.directory_for(name) File.join(ENV['HOME'], ".conjuror", name.to_s.gsub(/^\.+/, '')) end |
Instance Method Details
#[](key) ⇒ Object
def reload
self.use @name, @file
end
30 31 32 |
# File 'lib/conjuror/settings.rb', line 30 def [] key @data[key] end |
#[]=(key, value) ⇒ Object
ensures that every new setting is first persisted to the file.
35 36 37 38 39 |
# File 'lib/conjuror/settings.rb', line 35 def []= key, value @data[key] = value save_configuration value end |
#directory ⇒ Object
41 42 43 |
# File 'lib/conjuror/settings.rb', line 41 def directory self.class.directory_for(@name) end |
#path ⇒ Object
21 22 23 24 |
# File 'lib/conjuror/settings.rb', line 21 def path raise Conjuror::NoConfigurationLoadedError unless @name && @file File.join(self.directory, @file + ".yml") end |
#use(name = nil, file = nil) ⇒ Object
Returns an instance of the class itself.
10 11 12 13 14 |
# File 'lib/conjuror/settings.rb', line 10 def use name = nil, file = nil self.name = name self.file = file self end |