Class: Crowdkit::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/crowdkit/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(overrides = {}) {|_self| ... } ⇒ Config

Returns a new instance of Config.

Yields:

  • (_self)

Yield Parameters:



20
21
22
23
24
25
# File 'lib/crowdkit/config.rb', line 20

def initialize(overrides = {})
  @@config.each do |key,config|
    self.send("#{key}=", overrides[key] || ENV["CROWDKIT_#{key.upcase}"] || config[:value])
  end
  yield(self) if block_given?
end

Class Method Details

.config(key, value = nil, &block) ⇒ Object



3
4
5
6
7
# File 'lib/crowdkit/config.rb', line 3

def self.config(key, value = nil, &block)
  @@config ||= {}
  attr_accessor key
  @@config[key] = {value: value, block: block}
end

Instance Method Details

#connection_optionsObject



44
45
46
47
48
49
# File 'lib/crowdkit/config.rb', line 44

def connection_options
  {
    headers: { accept: "application/json", user_agent: self.user_agent },
    ssl: self.ssl
  }
end

#stack(&block) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/crowdkit/config.rb', line 27

def stack(&block)
  @stack ||= begin
    if block_given?
      Faraday::RackBuilder.new(&block)
    else
      Faraday::RackBuilder.new(&default_middleware)
    end
  end
end

#to_hashObject



37
38
39
40
41
42
# File 'lib/crowdkit/config.rb', line 37

def to_hash
  @@config.inject({}) do |memo,(key,value)|
    memo[key] = instance_variable_get(:"@#{key}")
    memo
  end
end