module NebulousStomp::Param
'Singleton' 'object' that stores parameters.
Constants
- ParamDefaults
Default parameters hash
- TargetDefaults
Default hash for each target
Public Instance Methods
Add a Nebulous target. Raises NebulousError
if anything looks screwy.
Parameters:
* t -- a Target
Used only by Nebulous::init
# 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 a the value of the parameter with the key p.
# File lib/nebulous_stomp/param.rb, line 80 def get(p) @params ||= ParamDefaults @params[p.to_sym] end
Get the whole parameter hash. Probably only useful for testing.
# File lib/nebulous_stomp/param.rb, line 73 def get_all() @params end
Get the logger instance
# File lib/nebulous_stomp/param.rb, line 68 def get_logger; @logger; end
Given a target name, return the corresponding Target
object
# 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 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().
# 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 a logger instance
# File lib/nebulous_stomp/param.rb, line 60 def set_logger(lg) fail NebulousError unless lg.kind_of?(Logger) || lg.nil? @logger = lg end
Private Instance Methods
reset all parameters – probably only useful for testing
# File lib/nebulous_stomp/param.rb, line 109 def reset @params = nil @logger = nil end
Raise an exception if a hash has any keys not found in an exemplar
(Private method, only called within Param
)
# File lib/nebulous_stomp/param.rb, line 100 def validate(exemplar, hash, message) hash.each_key do |k| fail NebulousError, "#{message} key '#{k}'" unless exemplar.include?(k) end end