Module: Namecheap::Config
Instance Attribute Summary collapse
-
#defaults ⇒ Object
Returns the value of attribute defaults.
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
-
#from_hash(options = {}) ⇒ Object
Configure namecheap from a hash.
-
#load!(path) ⇒ Object
Load the settings from a compliant namecheap.yml file.
-
#option(name, options = {}) ⇒ Object
Define a configuration option with a default.
-
#reset ⇒ Object
Reset the configuration options to the defaults.
Instance Attribute Details
#defaults ⇒ Object
Returns the value of attribute defaults.
7 8 9 |
# File 'lib/namecheap/config.rb', line 7 def defaults @defaults end |
#settings ⇒ Object
Returns the value of attribute settings.
7 8 9 |
# File 'lib/namecheap/config.rb', line 7 def settings @settings end |
Instance Method Details
#from_hash(options = {}) ⇒ Object
Configure namecheap from a hash. This is usually called after parsing a yaml config file such as mongoid.yml.
49 50 51 52 53 |
# File 'lib/namecheap/config.rb', line 49 def from_hash( = {}) .each_pair do |name, value| send("#{name}=", value) if respond_to?("#{name}=") end end |
#load!(path) ⇒ Object
Load the settings from a compliant namecheap.yml file. This can be used for easy setup with frameworks other than Rails.
62 63 64 65 66 67 |
# File 'lib/namecheap/config.rb', line 62 def load!(path) settings = YAML.load(ERB.new(File.new(path).read).result)[ENVIRONMENT] if settings.present? from_hash(settings) end end |
#option(name, options = {}) ⇒ Object
Define a configuration option with a default.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/namecheap/config.rb', line 20 def option(name, = {}) defaults[name] = settings[name] = [:default] class_eval " def \#{name}\n settings[\#{name.inspect}]\n end\n\n def \#{name}=(value)\n settings[\#{name.inspect}] = value\n end\n\n def \#{name}?\n \#{name}\n end\n RUBY\nend\n" |
#reset ⇒ Object
Reset the configuration options to the defaults.
73 74 75 |
# File 'lib/namecheap/config.rb', line 73 def reset settings.replace(defaults) end |