Class: MicroQ::Config

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

Instance Method Summary collapse

Constructor Details

#initializeConfig

Configuration accessible via:

  1. hash syntax (config and config = val)

  2. method syntax (config.k and config.k = val)

To change the type of worker that is used simply assign a new worker class (after requiring the file).



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/micro_q/config.rb', line 11

def initialize
  @data = {
    'workers' => 5,
    'timeout' => 120,
    'interval' => 5,
    'env' => defined?(Rails) ? Rails.env : 'development',
    'middleware' => Middleware::Chain.new,
    'manager' => Manager::Default,
    'worker' => Worker::Standard,
    'queue' => Queue::Default,
    'statistics' => Statistics::Default,
    'aws' => {},
    'redis_pool' => { :size => 15, :timeout => 1 },
    'redis' => { :host => 'localhost', :port => 6379 }
  }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



48
49
50
51
52
53
# File 'lib/micro_q/config.rb', line 48

def method_missing(method, *args)
  case method
    when /(.+)=$/ then @data[$1] = args.first
    else @data[method.to_s]
  end
end

Instance Method Details

#[](key) ⇒ Object



32
33
34
# File 'lib/micro_q/config.rb', line 32

def [](key)
  @data[key.to_s]
end

#[]=(key, value) ⇒ Object



28
29
30
# File 'lib/micro_q/config.rb', line 28

def []=(key, value)
  @data[key.to_s] = value
end

#queue=(q) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/micro_q/config.rb', line 36

def queue=(q)
  if q == Queue::Sqs
    require 'aws-sdk'

    @data['sqs?'] = true
  end

  @data['queue'] = q
rescue LoadError
  raise "Looks you need `gem 'aws-sdk'` in your Gemfile to use the SQS queue."
end