Class: Wamp::Worker::ConfigProxy
- Inherits:
-
Object
- Object
- Wamp::Worker::ConfigProxy
- 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
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#[](attribute) ⇒ Object
Gets the attribute using the name.
-
#[]=(attribute, value) ⇒ Object
Sets the attribute using the name.
-
#configure(&callback) ⇒ Object
Allows the user to configure without typing “config.”.
-
#connection(**options) ⇒ Object
Connection options.
-
#initialize(config, name = nil) ⇒ ConfigProxy
constructor
A new instance of ConfigProxy.
-
#redis(connection) ⇒ Object
Sets the Redis connection.
-
#register(procedure, klass, method, **options) ⇒ Object
Register the handler for a procedure.
-
#subscribe(topic, klass, method, **options) ⇒ Object
Subscribe the handler to a topic.
-
#timeout(seconds) ⇒ Object
Sets the timeout value.
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
44 45 46 |
# File 'lib/wamp/worker/config.rb', line 44 def config @config end |
#name ⇒ Object (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
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
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(**) self[:connection] = 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
87 88 89 90 91 |
# File 'lib/wamp/worker/config.rb', line 87 def register(procedure, klass, method, **) registrations = self[:registrations] || [] registrations << Registration.new(procedure, klass, method, ) self[:registrations] = registrations end |
#subscribe(topic, klass, method, **options) ⇒ Object
Subscribe the handler to a topic
75 76 77 78 79 |
# File 'lib/wamp/worker/config.rb', line 75 def subscribe(topic, klass, method, **) subscriptions = self[:subscriptions] || [] subscriptions << Subscription.new(topic, klass, method, ) 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 |