Class: Wamp::Worker::ConfigProxy

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

Overview

This class is a config proxy that lets you specify the name globally

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, name = nil) ⇒ ConfigProxy

Returns a new instance of ConfigProxy.



46
47
48
49
# File 'lib/wamp/worker/config.rb', line 46

def initialize(config, name=nil)
  @name = name || DEFAULT
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



44
45
46
# File 'lib/wamp/worker/config.rb', line 44

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name.



44
45
46
# File 'lib/wamp/worker/config.rb', line 44

def name
  @name
end

Instance Method Details

#[](attribute) ⇒ Object

Gets the attribute using the name

Parameters:

  • attribute (Symbol)
    • The attribute



110
111
112
# File 'lib/wamp/worker/config.rb', line 110

def [](attribute)
  self.config[self.name][attribute]
end

#[]=(attribute, value) ⇒ Object

Sets the attribute using the name

Parameters:

  • attribute (Symbol)
    • The attribute

  • value
    • The value for the attribute



103
104
105
# File 'lib/wamp/worker/config.rb', line 103

def []=(attribute, value)
  self.config[self.name][attribute] = value
end

#configure(&callback) ⇒ Object

Allows the user to configure without typing “config.”



95
96
97
# File 'lib/wamp/worker/config.rb', line 95

def configure(&callback)
  self.instance_eval(&callback)
end

#connection(**options) ⇒ Object

Connection options



65
66
67
# File 'lib/wamp/worker/config.rb', line 65

def connection(**options)
  self[:connection] = options
end

#redis(connection) ⇒ Object

Sets the Redis connection



59
60
61
# File 'lib/wamp/worker/config.rb', line 59

def redis(connection)
  self[:redis] = connection
end

#register(procedure, klass, method, **options) ⇒ Object

Register the handler for a procedure

Parameters:

  • procedure (String)
    • The procedure to register for

  • klass (Wamp::Worker::Handler)
    • The class to use

  • method (Symbol)
    • The name of the method to execute

  • options (Hash)
    • Options for the subscription



87
88
89
90
91
# File 'lib/wamp/worker/config.rb', line 87

def register(procedure, klass, method, **options)
  registrations = self[:registrations] || []
  registrations << Registration.new(procedure, klass, method, options)
  self[:registrations] = registrations
end

#subscribe(topic, klass, method, **options) ⇒ Object

Subscribe the handler to a topic

Parameters:

  • topic (String)
    • The topic to subscribe to

  • klass (Wamp::Worker::Handler)
    • The class to use

  • method (Symbol)
    • The name of the method to execute

  • options (Hash)
    • Options for the subscription



75
76
77
78
79
# File 'lib/wamp/worker/config.rb', line 75

def subscribe(topic, klass, method, **options)
  subscriptions = self[:subscriptions] || []
  subscriptions << Subscription.new(topic, klass, method, options)
  self[:subscriptions] = subscriptions
end

#timeout(seconds) ⇒ Object

Sets the timeout value



53
54
55
# File 'lib/wamp/worker/config.rb', line 53

def timeout(seconds)
  self[:timeout] = seconds
end