Module: Ahoy::Controller
- Defined in:
- lib/ahoy/controller.rb
Class Method Summary collapse
Instance Method Summary collapse
- #ahoy ⇒ Object
- #current_visit ⇒ Object
- #set_ahoy_cookies ⇒ Object
- #set_ahoy_request_store ⇒ Object
- #track_ahoy_visit ⇒ Object
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/ahoy/controller.rb', line 3 def self.included(base) if base.respond_to?(:helper_method) base.helper_method :current_visit base.helper_method :ahoy end base.before_action :track_ahoy_visit, unless: -> { Ahoy.api_only } base.around_action :set_ahoy_request_store, unless: -> { Ahoy.api_only } end |
Instance Method Details
#ahoy ⇒ Object
12 13 14 |
# File 'lib/ahoy/controller.rb', line 12 def ahoy @ahoy ||= Ahoy::Tracker.new(controller: self) end |
#current_visit ⇒ Object
16 17 18 |
# File 'lib/ahoy/controller.rb', line 16 def current_visit ahoy.visit end |
#set_ahoy_cookies ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/ahoy/controller.rb', line 20 def if Ahoy. ahoy. ahoy. else # delete cookies if exist ahoy.reset end end |
#set_ahoy_request_store ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/ahoy/controller.rb', line 46 def set_ahoy_request_store previous_value = Ahoy.instance begin Ahoy.instance = ahoy yield ensure Ahoy.instance = previous_value end end |
#track_ahoy_visit ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ahoy/controller.rb', line 30 def track_ahoy_visit defer = Ahoy.server_side_visits != true if defer && !Ahoy. # avoid calling new_visit?, which triggers a database call elsif !Ahoy. && ahoy.exclude? # avoid calling new_visit?, which triggers a database call # may or may not be a new visit Ahoy.log("Request excluded") elsif ahoy.new_visit? ahoy.track_visit(defer: defer) end end |