module RJR::HandlesMethods::ClassMethods
Attributes
jr_handlers[RW]
Public Instance Methods
create_handler_for(handler_method)
click to toggle source
Create handler for specified method.
Creates a proc that gets evaluated via instance_exec in request
# File lib/rjr/util/handles_methods.rb, line 70 def create_handler_for(handler_method) @jr_handlers ||= {} handler_class = self @jr_handlers[handler_method] = proc { |*args| # instantiate new handler instance jr_instance = handler_class.new # setup scope to include request variables instance_variables.each { |iv| jr_instance.instance_variable_set(iv, instance_variable_get(iv)) } # invoke handler method jr_instance.method(handler_method).call *args } end
dispatch_to(dispatcher)
click to toggle source
Register locally stored methods w/ the specified dispatcher
# File lib/rjr/util/handles_methods.rb, line 99 def dispatch_to(dispatcher) @jr_method_args.each { |args| # copy args so original is preserved handler_method, jr_methods = extract_handler_method(Array.new(args)) jr_methods.map! { |m| m.to_s } handler = has_handler_for?(handler_method) ? handler_for(handler_method) : create_handler_for(handler_method) dispatcher.handle jr_methods, handler } end
extract_handler_method(args)
click to toggle source
Return the handler method matching the argument set
# File lib/rjr/util/handles_methods.rb, line 42 def extract_handler_method(args) handler = nil if method_defined?(args.last) handler = args.last args.delete_at(-1) else handler = :handle end [handler, args] end
handler_for(handler_method)
click to toggle source
Returns handler for specified method
# File lib/rjr/util/handles_methods.rb, line 63 def handler_for(handler_method) @jr_handlers[handler_method] end
has_handler_for?(handler_method)
click to toggle source
Return bool indicating if handler exists for the specified method
# File lib/rjr/util/handles_methods.rb, line 57 def has_handler_for?(handler_method) @jr_handlers ||= {} @jr_handlers.has_key?(handler_method) end
jr_method(*args)
click to toggle source
Register one or more json-rpc methods.
Invoke w/ list of method signatures to match in dispatcher w/ optional id of local method to dispatch to. If no method specified, the :handle method will be used
# File lib/rjr/util/handles_methods.rb, line 93 def jr_method(*args) @jr_method_args ||= [] @jr_method_args << args end