Class: Flok::GotoHooksDSLEnv

Inherits:
Object
  • Object
show all
Defined in:
lib/flok/user_hook_generators/goto.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGotoHooksDSLEnv

Returns a new instance of GotoHooksDSLEnv.



5
6
7
8
9
# File 'lib/flok/user_hook_generators/goto.rb', line 5

def initialize
  @selectors = []
  @before_view_spider = {}
  @after_view_spider = {}
end

Instance Attribute Details

#after_view_spiderObject

Returns the value of attribute after_view_spider.



3
4
5
# File 'lib/flok/user_hook_generators/goto.rb', line 3

def after_view_spider
  @after_view_spider
end

#before_view_spiderObject

Returns the value of attribute before_view_spider.



3
4
5
# File 'lib/flok/user_hook_generators/goto.rb', line 3

def before_view_spider
  @before_view_spider
end

#selectorsObject

Returns the value of attribute selectors.



3
4
5
# File 'lib/flok/user_hook_generators/goto.rb', line 3

def selectors
  @selectors
end

Instance Method Details

#after_views(spider) ⇒ Object



82
83
84
# File 'lib/flok/user_hook_generators/goto.rb', line 82

def after_views spider
  @after_view_spider = spider
end

#before_views(spider) ⇒ Object



78
79
80
# File 'lib/flok/user_hook_generators/goto.rb', line 78

def before_views spider
  @before_view_spider = spider
end

#controller(name) ⇒ Object



11
12
13
# File 'lib/flok/user_hook_generators/goto.rb', line 11

def controller name
  @selectors << ->(p) { p["controller_name"] and p["controller_name"] == name.to_s }
end

#from_action(*names) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/flok/user_hook_generators/goto.rb', line 68

def from_action *names
  @selectors << lambda do |params|
    from_action = params["from_action"]

    next names.include? from_action
  end
end

#from_action_responds_to?(responds) ⇒ Boolean

The previous / next action contains an event handler for…

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/flok/user_hook_generators/goto.rb', line 17

def from_action_responds_to? responds
  @selectors << lambda do |params|
    from_action = params["from_action"]
    actions_respond_to = params["actions_responds_to"] #This is a hash that maps all actions to sensetivity lists

    #Get the sensetivity list if possible for this action (this is the list of events this action responds to)
    if actions_respond_to[from_action]
      sensetivity_list = actions_respond_to[from_action]

      #Does the sensetivity list include the event we are interested in?
      next sensetivity_list.include? responds
    end

    #The action wasn't even listed on the list, i.e. it has no sensetivity list
    next false
  end
end

#to_action(*names) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/flok/user_hook_generators/goto.rb', line 60

def to_action *names
  @selectors << lambda do |params|
    to_action = params["to_action"]

    next names.include? to_action
  end
end

#to_action_responds_to?(responds) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/flok/user_hook_generators/goto.rb', line 42

def to_action_responds_to? responds
  @selectors << lambda do |params|
    to_action = params["to_action"]
    actions_respond_to = params["actions_responds_to"] #This is a hash that maps all actions to sensetivity lists

    #Get the sensetivity list if possible for this action (this is the list of events this action responds to)
    if actions_respond_to[to_action]
      sensetivity_list = actions_respond_to[to_action]

      #Does the sensetivity list include the event we are interested in?
      next sensetivity_list.include? responds
    end

    #The action wasn't even listed on the list, i.e. it has no sensetivity list
    next false
  end
end

#triggered_by(event_name) ⇒ Object



35
36
37
38
39
40
# File 'lib/flok/user_hook_generators/goto.rb', line 35

def triggered_by event_name
  @selectors << lambda do |params|
    handling_event_named = params["handling_event_named"]
    next handling_event_named == event_name
  end
end