Class: Apotomo::RequestProcessor
- Inherits:
-
Object
- Object
- Apotomo::RequestProcessor
- Includes:
- Hooks
- Defined in:
- lib/apotomo/request_processor.rb
Defined Under Namespace
Classes: InvalidSourceWidget
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#address_for(options) ⇒ Object
Computes the address hash for a
:source
widget and an event:type
. - #attach_stateless_blocks_for(blocks, root, controller) ⇒ Object
-
#initialize(controller, options = {}, has_widgets_blocks = []) ⇒ RequestProcessor
constructor
A new instance of RequestProcessor.
-
#process_for(request_params) ⇒ Object
Called when the browser wants an url_for_event address.
-
#render_widget_for(*args) ⇒ Object
Renders the widget named
widget_id
.
Constructor Details
#initialize(controller, options = {}, has_widgets_blocks = []) ⇒ RequestProcessor
Returns a new instance of RequestProcessor.
14 15 16 17 18 19 20 |
# File 'lib/apotomo/request_processor.rb', line 14 def initialize(controller, ={}, =[]) @root = Widget.new(controller, :root) attach_stateless_blocks_for(, @root, controller) run_hook :after_initialize, self end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
11 12 13 |
# File 'lib/apotomo/request_processor.rb', line 11 def root @root end |
Instance Method Details
#address_for(options) ⇒ Object
Computes the address hash for a :source
widget and an event :type
. Additional parameters will be merged.
44 45 46 47 |
# File 'lib/apotomo/request_processor.rb', line 44 def address_for() # DISCUSS: remove/make private/rename? raise "You forgot to provide :source or :type" unless .has_key?(:source) and .has_key?(:type) end |
#attach_stateless_blocks_for(blocks, root, controller) ⇒ Object
22 23 24 |
# File 'lib/apotomo/request_processor.rb', line 22 def attach_stateless_blocks_for(blocks, root, controller) blocks.each { |blk| controller.instance_exec(root, &blk) } end |
#process_for(request_params) ⇒ Object
Called when the browser wants an url_for_event address. This fires the request event in the widget tree and collects the rendered page updates.
28 29 30 31 32 33 34 35 |
# File 'lib/apotomo/request_processor.rb', line 28 def process_for(request_params) source = self.root.(request_params[:source]) or raise InvalidSourceWidget, "Source #{request_params[:source].inspect} non-existent." source.fire(request_params[:type].to_sym, request_params) # set data to params for now. run_hook :after_fire, self source.root.page_updates ### DISCUSS: that's another dependency. end |
#render_widget_for(*args) ⇒ Object
Renders the widget named widget_id
. Any additional args is passed through to Widget#invoke.
38 39 40 |
# File 'lib/apotomo/request_processor.rb', line 38 def (*args) root.(*args) end |