Sha256: 4219cb66b86cdbc3d026c55f2fa899052c913213ab9f84c4e79980c5ffd6d4eb

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

module OmiseGO
  class Configuration
    OPTIONS = {
      access_key: -> { ENV['OMISEGO_ACCESS_KEY'] },
      secret_key: -> { ENV['OMISEGO_SECRET_KEY'] },
      base_url: -> { ENV['OMISEGO_BASE_URL'] },
      logger: nil
    }.freeze

    OMISEGO_OPTIONS = {
      api_version: '1',
      auth_scheme: 'OMGServer',
      models: {
        user: OmiseGO::User,
        error: OmiseGO::Error,
        authentication_token: OmiseGO::AuthenticationToken,
        address: OmiseGO::Address,
        balance: OmiseGO::Balance,
        minted_token: OmiseGO::MintedToken,
        list: OmiseGO::List,
        setting: OmiseGO::Setting,
        transaction: OmiseGO::Transaction,
        exchange: OmiseGO::Exchange,
        transaction_source: OmiseGO::TransactionSource
      }
    }.freeze

    attr_accessor(*OPTIONS.keys)
    attr_reader(*OMISEGO_OPTIONS.keys)

    def initialize(options = {})
      OPTIONS.each do |name, val|
        value = options ? options[name] || options[name.to_sym] : nil
        value ||= val.call if val.respond_to?(:call)
        instance_variable_set("@#{name}", value)
      end

      OMISEGO_OPTIONS.each do |name, value|
        instance_variable_set("@#{name}", value)
      end
    end

    def [](option)
      instance_variable_get("@#{option}")
    end

    def to_hash
      OPTIONS.keys.each_with_object({}) do |option, hash|
        hash[option.to_sym] = self[option]
      end
    end

    def merge(options)
      OPTIONS.each_key do |name|
        instance_variable_set("@#{name}", options[name]) if options[name]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
omisego-0.9.6 lib/omisego/configuration.rb
omisego-0.9.5 lib/omisego/configuration.rb
omisego-0.9.4 lib/omisego/configuration.rb