class Controll::Flow::ActionMapper::Simple
Constants
- NoDefaultPathDefinedError
- NoEventsDefinedError
Public Class Methods
action(controller, event, path = nil)
click to toggle source
# File lib/controll/flow/action_mapper/simple.rb, line 15 def action controller, event, path = nil check! event = normalize event path_action_class.new(controller, path || default_path) if events.include? event.name end
default_path(str = nil, &block)
click to toggle source
bugs.ruby-lang.org/issues/1082
hello.singleton_class
Instead of always having to write:
(class << hello; self; end)
# File lib/controll/flow/action_mapper/simple.rb, line 25 def default_path str = nil, &block (class << self; self; end).send :define_method, :default_path do block_given? ? instance_eval(&block) : str end end
events(*args, &block)
click to toggle source
# File lib/controll/flow/action_mapper/simple.rb, line 31 def events *args, &block (class << self; self; end).send :define_method, :events do args.flatten end default_path(&block) if block_given? end
inherited(base)
click to toggle source
# File lib/controll/flow/action_mapper/simple.rb, line 9 def inherited base if base.parent.respond_to? :add_action_handler base.add_action_handler self.name.demodulize end end
Protected Class Methods
check!()
click to toggle source
# File lib/controll/flow/action_mapper/simple.rb, line 41 def check! unless respond_to?(:events) && !events.blank? raise NoEventsDefinedError, "You must define the events/actions that can be mapped by this class" end unless respond_to?(:default_path) && !default_path.blank? raise NoDefaultPathDefinedError, "You must set a default_path to be routed to if no event/action matches" end end