Module: Namecheap::Config
Defined Under Namespace
Classes: RequiredOptionMissing
Constant Summary collapse
- ENVIRONMENTS =
%w[sandbox production].freeze
Instance Attribute Summary collapse
-
#client_ip ⇒ Object
Returns the value of attribute client_ip.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#key ⇒ Object
Returns the value of attribute key.
-
#username ⇒ Object
Returns the value of attribute username.
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.
Instance Attribute Details
#client_ip ⇒ Object
Returns the value of attribute client_ip.
11 12 13 |
# File 'lib/namecheap/config.rb', line 11 def client_ip @client_ip end |
#environment ⇒ Object
Returns the value of attribute environment.
12 13 14 |
# File 'lib/namecheap/config.rb', line 12 def environment @environment end |
#key ⇒ Object
Returns the value of attribute key.
11 12 13 |
# File 'lib/namecheap/config.rb', line 11 def key @key end |
#username ⇒ Object
Returns the value of attribute username.
11 12 13 |
# File 'lib/namecheap/config.rb', line 11 def username @username 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.
31 32 33 34 35 |
# File 'lib/namecheap/config.rb', line 31 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.
44 45 46 47 48 |
# File 'lib/namecheap/config.rb', line 44 def load!(path) contents = ERB.new(File.read(path)).result settings = YAML.safe_load(contents, aliases: true)&.fetch(Namecheap::Api::ENVIRONMENT, nil) from_hash(settings) if settings && !settings.empty? end |