Module: NebulousStomp::Param
Overview
‘Singleton’ ‘object’ that stores parameters.
Constant Summary collapse
- ParamDefaults =
Default parameters hash
{ stompConnectHash: {}, redisConnectHash: {}, messageTimeout: 10, cacheTimeout: 120, logger: nil, targets: {} }
- TargetDefaults =
Default hash for each target
{ sendQueue: nil, receiveQueue: nil, messageTimeout: nil }
Instance Method Summary collapse
-
#add_target(t) ⇒ Object
Add a Nebulous target.
-
#get(p) ⇒ Object
Get a the value of the parameter with the key p.
-
#get_all ⇒ Object
Get the whole parameter hash.
-
#get_logger ⇒ Object
Get the logger instance.
-
#get_target(name) ⇒ Object
Given a target name, return the corresponding Target object.
-
#set(p = {}) ⇒ Object
Set the initial parameter string.
-
#set_logger(lg) ⇒ Object
Set a logger instance.
Instance Method Details
#add_target(t) ⇒ Object
Add a Nebulous target. Raises NebulousError if anything looks screwy.
Parameters:
* t -- a Target
Used only by Nebulous::init
50 51 52 53 54 55 |
# File 'lib/nebulous_stomp/param.rb', line 50 def add_target(t) fail NebulousError, "Invalid target" unless t.kind_of?(Target) @params ||= ParamDefaults @params[:targets][t.name.to_sym] = t end |
#get(p) ⇒ Object
Get a the value of the parameter with the key p.
80 81 82 83 |
# File 'lib/nebulous_stomp/param.rb', line 80 def get(p) @params ||= ParamDefaults @params[p.to_sym] end |
#get_all ⇒ Object
Get the whole parameter hash. Probably only useful for testing.
73 74 75 |
# File 'lib/nebulous_stomp/param.rb', line 73 def get_all() @params end |
#get_logger ⇒ Object
Get the logger instance
68 |
# File 'lib/nebulous_stomp/param.rb', line 68 def get_logger; @logger; end |
#get_target(name) ⇒ Object
Given a target name, return the corresponding Target object
88 89 90 91 |
# File 'lib/nebulous_stomp/param.rb', line 88 def get_target(name) t = Param.get(:targets) (t && t.kind_of?(Hash)) ? t[name.to_s.to_sym] : nil end |
#set(p = {}) ⇒ Object
Set the initial parameter string. This also has the effect of resetting everything.
Parameters default to Param::ParamDefaults. keys passed in parameter p to override those defaults must match, or a NebulousError will result.
This method is only called by Nebulous::init().
34 35 36 37 38 39 40 |
# File 'lib/nebulous_stomp/param.rb', line 34 def set(p={}) fail NebulousError, "Invalid initialisation hash" unless p.kind_of?(Hash) validate(ParamDefaults, p, "Unknown initialisation hash") @params = ParamDefaults.merge(p) end |
#set_logger(lg) ⇒ Object
Set a logger instance
60 61 62 63 |
# File 'lib/nebulous_stomp/param.rb', line 60 def set_logger(lg) fail NebulousError unless lg.kind_of?(Logger) || lg.nil? @logger = lg end |