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.



7
8
9
10
11
# File 'lib/flok/user_hook_generators/goto.rb', line 7

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

Instance Attribute Details

#after_view_spiderObject

Returns the value of attribute after_view_spider.



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

def after_view_spider
  @after_view_spider
end

#before_view_spiderObject

Returns the value of attribute before_view_spider.



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

def before_view_spider
  @before_view_spider
end

#selectorsObject

Returns the value of attribute selectors.



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

def selectors
  @selectors
end

Instance Method Details

#after_views(spider) ⇒ Object



60
61
62
# File 'lib/flok/user_hook_generators/goto.rb', line 60

def after_views spider
  @after_view_spider = spider
end

#before_views(spider) ⇒ Object



56
57
58
# File 'lib/flok/user_hook_generators/goto.rb', line 56

def before_views spider
  @before_view_spider = spider
end

#controller(name) ⇒ Object



13
14
15
# File 'lib/flok/user_hook_generators/goto.rb', line 13

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

#from_action_responds_to?(responds) ⇒ Boolean

The previous / next action contains an event handler for…

Returns:

  • (Boolean)


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

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_responds_to?(responds) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/flok/user_hook_generators/goto.rb', line 37

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