Class: Apotomo::RequestProcessor

Inherits:
Object
  • Object
show all
Includes:
Hooks
Defined in:
lib/apotomo/request_processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, options = {}, has_widgets_blocks = []) ⇒ RequestProcessor

Returns a new instance of RequestProcessor.



11
12
13
14
15
16
17
# File 'lib/apotomo/request_processor.rb', line 11

def initialize(controller, options={}, has_widgets_blocks=[])
  @root = Widget.new(controller, 'root', :display)
  
  attach_stateless_blocks_for(has_widgets_blocks, @root, controller)
  
  run_hook :after_initialize, self
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



8
9
10
# File 'lib/apotomo/request_processor.rb', line 8

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.



41
42
43
44
# File 'lib/apotomo/request_processor.rb', line 41

def address_for(options)
  raise "You forgot to provide :source or :type" unless options.has_key?(:source) and options.has_key?(:type)
  options
end

#attach_stateless_blocks_for(blocks, root, controller) ⇒ Object



19
20
21
# File 'lib/apotomo/request_processor.rb', line 19

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.



25
26
27
28
29
30
31
32
# File 'lib/apotomo/request_processor.rb', line 25

def process_for(request_params)
  source = self.root.find_widget(request_params[:source]) or raise "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.



35
36
37
# File 'lib/apotomo/request_processor.rb', line 35

def render_widget_for(*args)
  root.render_widget(*args)
end