Module: Namecheap::Config

Extended by:
Config
Included in:
Config
Defined in:
lib/namecheap/config.rb

Defined Under Namespace

Classes: RequiredOptionMissing

Constant Summary collapse

ENVIRONMENTS =
%w[sandbox production].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#client_ipObject

Returns the value of attribute client_ip.



11
12
13
# File 'lib/namecheap/config.rb', line 11

def client_ip
  @client_ip
end

#environmentObject

Returns the value of attribute environment.



12
13
14
# File 'lib/namecheap/config.rb', line 12

def environment
  @environment
end

#keyObject

Returns the value of attribute key.



11
12
13
# File 'lib/namecheap/config.rb', line 11

def key
  @key
end

#usernameObject

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.

Examples:

Configure Namecheap.

config.from_hash({})

Parameters:

  • options (Hash) (defaults to: {})

    The settings to use.



31
32
33
34
35
# File 'lib/namecheap/config.rb', line 31

def from_hash(options = {})
  options.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.

Examples:

Configure Namecheap.

Namecheap.load!("/path/to/namecheap.yml")

Parameters:

  • path (String)

    The path to the file.



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