Module: Stenotype::Frameworks::Rails::ActionControllerExtension::ClassMethods
- Defined in:
- lib/stenotype/frameworks/rails/action_controller.rb
Overview
Class methods to be injected into classes inherited from [ActionController::Base]
Instance Method Summary collapse
-
#track_all_views ⇒ Object
the tracked actions and the ones not tracked yet.
-
#track_view(*actions) ⇒ Object
Adds a before_action to each action from the passed list.
Instance Method Details
#track_all_views ⇒ Object
Note:
This action will only define a symmetric difference of
the tracked actions and the ones not tracked yet.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/stenotype/frameworks/rails/action_controller.rb', line 104 def track_all_views actions = action_methods # A symmetric difference of two sets. # This prevents accidental duplicating of events delta = ((_tracked_actions - actions) | (actions - _tracked_actions)) return if delta.empty? before_action only: delta.to_a do _record_freshly_event("view") end # merge is a mutating op _tracked_actions.merge(delta) end |
#track_view(*actions) ⇒ Object
Note:
Each time a new track_view is called it will find a symmetric difference
of two sets: set of already tracked actions and a set passed to track_view
.
Adds a before_action to each action from the passed list. A before action is emitting a Event. Please note that in case track_view is used several times, it will keep track of the actions which emit events.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/stenotype/frameworks/rails/action_controller.rb', line 68 def track_view(*actions) # A symmetric difference of two sets. # This prevents accidental duplicating of events delta = (_tracked_actions - Set[*actions]) | (Set[*actions] - _tracked_actions) return if delta.empty? before_action only: delta do _record_freshly_event("view") end _tracked_actions.merge(delta) end |