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
- #reload ⇒ 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
50 51 52 53 54 |
# File 'lib/conjuror/settings.rb', line 50 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
56 57 58 |
# File 'lib/conjuror/settings.rb', line 56 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
34 35 36 37 |
# File 'lib/conjuror/settings.rb', line 34 def [] key self.reload @data[key] end |
#[]=(key, value) ⇒ Object
ensures that every new setting is first persisted to the file.
40 41 42 43 44 |
# File 'lib/conjuror/settings.rb', line 40 def []= key, value @data[key] = value save_configuration value end |
#directory ⇒ Object
46 47 48 |
# File 'lib/conjuror/settings.rb', line 46 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 |
#reload ⇒ Object
26 27 28 |
# File 'lib/conjuror/settings.rb', line 26 def reload self.use @name, @file 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 |