Sha256: 8220fc4aeb0e15bdc5096fc4bedca3ff2e9b32b4548fe84cc4036ed0031d2afc

Contents?: true

Size: 1.06 KB

Versions: 5

Compression:

Stored size: 1.06 KB

Contents

module Nearmiss
  module Configurable
    
    attr_accessor :middleware, :proxy, :user_agent, :connection_options, :api_key, :auto_paginate, :per_page
    attr_writer :password, :api_endpoint, :email

    # Define static methods
    class << self
      
      def keys
        @keys ||= [
          :middleware,
          :proxy,
          :user_agent,
          :connection_options,
          :password,
          :api_endpoint,
          :api_key,
          :email,
          :auto_paginate,
          :per_page
        ]
      end
    end

    # Set configuration options using a block
    def configure
      yield self
    end

    # Reset configuration options to default values
    def reset!
      Nearmiss::Configurable.keys.each do |key|
        instance_variable_set(:"@#{key}", Nearmiss::Default.options[key])
      end
      self
    end
    alias setup reset!

    def api_endpoint
      File.join(@api_endpoint, "")
    end

    def options
      Hash[Nearmiss::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}]
    end

  private


  
  end  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nearmiss-ruby-1.0.4 lib/nearmiss-ruby/configurable.rb
nearmiss-ruby-1.0.3 lib/nearmiss-ruby/configurable.rb
nearmiss-ruby-1.0.2 lib/nearmiss-ruby/configurable.rb
nearmiss-ruby-1.0.1 lib/nearmiss-ruby/configurable.rb
nearmiss-ruby-1.0.0 lib/nearmiss-ruby/configurable.rb