Class: Reactive::OutputHandler::Base
- Defined in:
- lib/reactive-core/output_handler.rb
Defined Under Namespace
Classes: ProxyModule
Constant Summary collapse
- @@output_handlers =
{}
- @@helper_modules =
{}
Instance Attribute Summary collapse
-
#helpers ⇒ Object
readonly
Returns the value of attribute helpers.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
- .helper(format, mod) ⇒ Object
- .helper_module(format) ⇒ Object
- .output_handler(format, name) ⇒ Object
- .output_handlers(format) ⇒ Object
- .process(request, response) ⇒ Object
- .register_output_handler(format, handler) ⇒ Object
Instance Method Summary collapse
- #action_name ⇒ Object
- #controller_name ⇒ Object
- #request_name ⇒ Object
- #treat(request, response) ⇒ Object
Instance Attribute Details
#helpers ⇒ Object (readonly)
Returns the value of attribute helpers.
113 114 115 |
# File 'lib/reactive-core/output_handler.rb', line 113 def helpers @helpers end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
113 114 115 |
# File 'lib/reactive-core/output_handler.rb', line 113 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
113 114 115 |
# File 'lib/reactive-core/output_handler.rb', line 113 def response @response end |
Class Method Details
.helper(format, mod) ⇒ Object
29 30 31 |
# File 'lib/reactive-core/output_handler.rb', line 29 def helper(format, mod) helper_module(format).send(:include, mod) end |
.helper_module(format) ⇒ Object
33 34 35 |
# File 'lib/reactive-core/output_handler.rb', line 33 def helper_module(format) @@helper_modules[format] ||= Module.new end |
.output_handler(format, name) ⇒ Object
25 26 27 |
# File 'lib/reactive-core/output_handler.rb', line 25 def output_handler(format, name) output_handlers(format).find {|handler| handler.handler_name == name} end |
.output_handlers(format) ⇒ Object
21 22 23 |
# File 'lib/reactive-core/output_handler.rb', line 21 def output_handlers(format) @@output_handlers[format] ||= [] end |
.process(request, response) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/reactive-core/output_handler.rb', line 37 def process(request, response) # a 'false' handler is used to disable output handling if response.handler_name == false logger.info "Handling disabled for #{request.params.inspect}" return response.body end # logger.info "Handling #{response.handler_name}/#{response.treatment} for format #{response.format}" handler = pick_handler(response.format, response.handler_name) raise NoHandlerFound, "Requested output handler #{response.handler_name} for format #{response.format} not available!" unless handler # handler_instance(handler).treat(request, response) rescue Exception => exception log_error(exception) raise exception end |
.register_output_handler(format, handler) ⇒ Object
17 18 19 |
# File 'lib/reactive-core/output_handler.rb', line 17 def register_output_handler(format, handler) output_handlers(format) << handler end |
Instance Method Details
#action_name ⇒ Object
125 126 127 |
# File 'lib/reactive-core/output_handler.rb', line 125 def action_name @request.params[:action].to_s end |
#controller_name ⇒ Object
121 122 123 |
# File 'lib/reactive-core/output_handler.rb', line 121 def controller_name @request.params[:controller].to_s end |
#request_name ⇒ Object
129 130 131 |
# File 'lib/reactive-core/output_handler.rb', line 129 def request_name "request_#{controller_name}_#{action_name}" end |
#treat(request, response) ⇒ Object
115 116 117 118 119 |
# File 'lib/reactive-core/output_handler.rb', line 115 def treat(request, response) @request, @response = request, response setup_helpers send(response.treatment || default_treatment) end |