Class: Controll::Flow::ActionMapper::Simple

Inherits:
Base
  • Object
show all
Extended by:
Event::Helper
Defined in:
lib/controll/flow/action_mapper/simple.rb

Constant Summary collapse

NoEventsDefinedError =
Controll::Flow::NoEventsDefinedError
NoDefaultPathDefinedError =
Controll::Flow::NoDefaultPathDefinedError

Class Method Summary collapse

Methods included from Event::Helper

create_event, normalize

Methods inherited from Base

path_action_class

Class Method Details

.action(controller, event, path = nil) ⇒ Object



15
16
17
18
19
# 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) ⇒ Object

bugs.ruby-lang.org/issues/1082

hello.singleton_class

Instead of always having to write:

(class << hello; self; end)


25
26
27
28
29
# 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) ⇒ Object



31
32
33
34
35
36
37
# 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) ⇒ Object



9
10
11
12
13
# 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