Class: Flok::UserCompilerContext

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUserCompilerContext

Returns a new instance of UserCompilerContext.



30
31
32
33
34
35
36
# File 'lib/flok/user_compiler.rb', line 30

def initialize
  @controllers = []
  @actions = []
  @ons = []

  @debug = ENV["FLOK_ENV"] ? true : false
end

Instance Attribute Details

#actionsObject

Returns the value of attribute actions.



28
29
30
# File 'lib/flok/user_compiler.rb', line 28

def actions
  @actions
end

#controllersObject

Returns the value of attribute controllers.



28
29
30
# File 'lib/flok/user_compiler.rb', line 28

def controllers
  @controllers
end

#onsObject

Returns the value of attribute ons.



28
29
30
# File 'lib/flok/user_compiler.rb', line 28

def ons
  @ons
end

Instance Method Details

#action(controller, name, &block) ⇒ Object



59
60
61
# File 'lib/flok/user_compiler.rb', line 59

def action controller, name, &block
  @actions << UserCompilerAction.new(controller, name, self, &block)
end

#actions_for_controller(controller_name) ⇒ Object



66
67
68
# File 'lib/flok/user_compiler.rb', line 66

def actions_for_controller controller_name
  return @actions.select{|e| e.controller.name == controller_name}
end

#actions_respond_toObject

actions_responds_to looks like {“action1” => [“event_a”, …“], ”action2“ => }… where each action list contains all the events this action responds to



47
48
49
# File 'lib/flok/user_compiler.rb', line 47

def actions_respond_to
  @actions.map{|e| [e.name.to_s, e.ons.map{|e| e[:name].to_s}]}.to_h
end

#controller(name, &block) ⇒ Object



55
56
57
# File 'lib/flok/user_compiler.rb', line 55

def controller name, &block
  @controllers << UserCompilerController.new(name, self, &block)
end

#get_bindingObject



51
52
53
# File 'lib/flok/user_compiler.rb', line 51

def get_binding
  return binding
end

#might_respond_toObject

Returns a list of events that this controller ‘might’ respond to Used for things like hook event handlers to provide queryable information.



41
42
43
# File 'lib/flok/user_compiler.rb', line 41

def might_respond_to
  @actions.map{|e| e.ons}.flatten.map{|e| e[:name]}
end

#on(controller_name, action_name, name, &block) ⇒ Object



63
64
# File 'lib/flok/user_compiler.rb', line 63

def on controller_name, action_name, name, &block
end

#spots_for_controller(controller_name) ⇒ Object



70
71
72
# File 'lib/flok/user_compiler.rb', line 70

def spots_for_controller controller_name
  return @controllers.detect{|e| e.name == controller_name}.spots
end