Class: Wamp::Worker::Config

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

Overview

This class is used to store the configuration of the worker

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



120
121
122
# File 'lib/wamp/worker/config.rb', line 120

def initialize
  @settings = {}
end

Instance Attribute Details

#settingsObject (readonly)

Returns the value of attribute settings.



118
119
120
# File 'lib/wamp/worker/config.rb', line 118

def settings
  @settings
end

Instance Method Details

#[](name) ⇒ Object

Returns the settings for a particular connection

Parameters:

  • name (Symbol)
    • The name of the connection



176
177
178
179
180
# File 'lib/wamp/worker/config.rb', line 176

def [](name)
  settings = self.settings[name] || {}
  self.settings[name] = settings
  settings
end

#connection(name = nil) ⇒ Object

Returns the connection options

Parameters:

  • name (Symbol) (defaults to: nil)
    • The name of the connection



127
128
129
130
# File 'lib/wamp/worker/config.rb', line 127

def connection(name=nil)
  name ||= DEFAULT
  self[name][:connection] || {}
end

#redis(name = nil) ⇒ Object

Returns the redis value

Parameters:

  • name (Symbol) (defaults to: nil)
    • The name of the connection



143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/wamp/worker/config.rb', line 143

def redis(name=nil)
  name ||= DEFAULT
  redis = self[name][:redis]

  # If it is not a redis object, create one using it as the options
  if redis == nil
    redis = ::Redis.new
  elsif not redis.is_a? ::Redis
    redis = ::Redis.new(redis)
  end

  redis
end

#registrations(name = nil) ⇒ Object

Returns the registrations

Parameters:

  • name (Symbol) (defaults to: nil)
    • The name of the connection



168
169
170
171
# File 'lib/wamp/worker/config.rb', line 168

def registrations(name=nil)
  name ||= DEFAULT
  self[name][:registrations] || []
end

#subscriptions(name = nil) ⇒ Object

Returns the subscriptions

Parameters:

  • name (Symbol) (defaults to: nil)
    • The name of the connection



160
161
162
163
# File 'lib/wamp/worker/config.rb', line 160

def subscriptions(name=nil)
  name ||= DEFAULT
  self[name][:subscriptions] || []
end

#timeout(name = nil) ⇒ Object

Returns the timeout value

Parameters:

  • name (Symbol) (defaults to: nil)
    • The name of the connection



135
136
137
138
# File 'lib/wamp/worker/config.rb', line 135

def timeout(name=nil)
  name ||= DEFAULT
  self[name][:timeout] || 60
end