Sha256: 019a35e8f82b2eba2c3ff73e3543cecb01db7919261a289e113d3b31d8017312

Contents?: true

Size: 1003 Bytes

Versions: 2

Compression:

Stored size: 1003 Bytes

Contents

# encoding: utf-8
module ShareChecker
  class Config < Hash
    # Creates an accessor that simply sets and reads a key in the hash:
    #
    # class Config < Hash
    #   hash_accessor :routes, :secret_key, :service_number, :project_name
    # end
    #
    # config = Config.new
    # config.routes = '/posts/message'
    # config[:routes] #=> '/posts/message'
    #
    def self.hash_accessor(*names) #:nodoc:
      names.each do |name|
        class_eval <<-METHOD, __FILE__, __LINE__ + 1
          def #{name}
            self[:#{name}]
          end

          def #{name}=(value)
            self[:#{name}] = value
          end
        METHOD
      end
    end
    
    hash_accessor *Providers.avariable
    hash_accessor :timeout, :user_agent
    
    def initialize(other = {})
      merge!(other)
      
      self[:timeout] ||= 30
      self[:user_agent] ||= "ShareChecker Robot"
      
      Providers.avariable.each do |provider|
        self[provider] ||= {}
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
share_checker-0.1.7 lib/share_checker/config.rb
share_checker-0.1.6 lib/share_checker/config.rb