class Apotomo::RequestProcessor

Attributes

root[R]

Public Class Methods

new(controller, options={}, has_widgets_blocks=[]) click to toggle source
# File lib/apotomo/request_processor.rb, line 14
def initialize(controller, options={}, has_widgets_blocks=[])
  @root = Widget.new(controller, :root)
  
  attach_stateless_blocks_for(has_widgets_blocks, @root, controller)
  
  run_hook :after_initialize, self
end

Public Instance Methods

address_for(options) click to toggle source

Computes the address hash for a :source widget and an event :type. Additional parameters will be merged.

# File lib/apotomo/request_processor.rb, line 44
def address_for(options) # DISCUSS: remove/make private/rename?
  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) click to toggle source
# 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) click to toggle source

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.

# File lib/apotomo/request_processor.rb, line 28
def process_for(request_params)
  source = self.root.find_widget(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) click to toggle source

Renders the widget named widget_id. Any additional args is passed through to Widget#invoke.

# File lib/apotomo/request_processor.rb, line 38
def render_widget_for(*args)
  root.render_widget(*args)
end