class SendWithUs::Config

Constants

DEFAULT_URL

attr_writer :url, :api_key, :protocol, :host, :port, :api_version, :debug

Attributes

settings[RW]

Public Class Methods

defaults() click to toggle source
# File lib/send_with_us/config.rb, line 10
def self.defaults
  source = URI.parse(DEFAULT_URL)

  {
    url: DEFAULT_URL,
    api_key:      nil,
    protocol:     source.scheme,
    host:         source.host,
    port:         source.port,
    api_version:  '1',
    debug:        true,
    client_stub:  "ruby-#{VERSION}"
  }
end
new(options={}) click to toggle source
# File lib/send_with_us/config.rb, line 25
def initialize(options={})
  @settings = SendWithUs::Config.defaults.merge(options)
end

Public Instance Methods

method_missing(meth, *args, &block) click to toggle source
Calls superclass method
# File lib/send_with_us/config.rb, line 29
def method_missing(meth, *args, &block)
  meth_str = meth.to_s

  if meth_str.include?('=')
    # If this is a write attempt, see if we can write to that key
    meth_sym = meth_str.gsub('=', '').to_sym
    has?(meth_sym) ? @settings[meth_sym] = args[0] : super
  else
    # It's a read attempt, see if that key exists
    has?(meth) ? @settings[meth] : super
  end
end
respond_to_missing?(meth, include_private = false) click to toggle source
Calls superclass method
# File lib/send_with_us/config.rb, line 42
def respond_to_missing?(meth, include_private = false)
  has?(meth) || super
end

Private Instance Methods

has?(key) click to toggle source
# File lib/send_with_us/config.rb, line 48
def has?(key)
  @settings.has_key?(key)
end