Sha256: 3badcbe362768a6ec0c48e5caf7e457d710d7fc63567b6d779481a7a0393b7c3

Contents?: true

Size: 1.61 KB

Versions: 8

Compression:

Stored size: 1.61 KB

Contents

module Trackerific
  # Provides a dynamic configuration
  class Configuration
    include OptionsHelper
    # Creates a new instance of Trackerific::Configuration
    # @api private
    def initialize
      @options = {}
    end
    # Overriding the method_missing method allows dynamic methods
    # @return [Hash]
    # @api private
    def method_missing(sym, *args, &block)
      # Get a list of all the services (convert symbols to lower case)
      services = Trackerific.services.map { |service| service.to_s.downcase.to_sym }
      # Do not accept any configuration values for anything except services
      raise NoMethodError unless services.include? sym
      unless args.empty?
        # Only accept Hashes
        raise ArgumentError unless args[0].class == Hash
        # Validate configuration values against the required options for that service
        validate_options args[0], Trackerific.service_get(sym).required_options
        # Store the configuration options
        @options[sym] = args[0]
      end
      # return the configuration options
      @options[sym]
    end
  end
  class << self
    # Stores the configuration options for Trackerific
    # @return [Trackerific::Configuration]
    # @api private
    def configuration
      @configuration ||= Trackerific::Configuration.new
    end
    # Configures Trackerific
    # @return [Trackerific::Configuration]
    # @example Defining credentials
    #   Trackerific.configure do |config|
    #     config.fedex :meter => '123456789', :account => '123456789'
    #   end
    # @api public
    def configure
      yield configuration
      configuration
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
trackerific-0.5.5 lib/trackerific/configuration.rb
trackerific-0.5.4 lib/trackerific/configuration.rb
trackerific-0.5.3 lib/trackerific/configuration.rb
trackerific-0.5.2 lib/trackerific/configuration.rb
trackerific-0.5.1 lib/trackerific/configuration.rb
trackerific-0.5.0 lib/trackerific/configuration.rb
trackerific-0.4.2 lib/trackerific/configuration.rb
trackerific-0.4.1 lib/trackerific/configuration.rb