Class: Ahoy::Stores::ActiveRecordTokenStore
- Inherits:
-
BaseStore
- Object
- BaseStore
- Ahoy::Stores::ActiveRecordTokenStore
show all
- Defined in:
- lib/ahoy/stores/active_record_token_store.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseStore
#authenticate, #generate_id, #initialize, #report_exception
Class Method Details
.uses_deprecated_subscribers ⇒ Object
92
93
94
95
|
# File 'lib/ahoy/stores/active_record_token_store.rb', line 92
def uses_deprecated_subscribers
warn "[DEPRECATION] Ahoy subscribers are deprecated"
@uses_deprecated_subscribers = true
end
|
.uses_deprecated_subscribers? ⇒ Boolean
97
98
99
|
# File 'lib/ahoy/stores/active_record_token_store.rb', line 97
def uses_deprecated_subscribers?
@uses_deprecated_subscribers || false
end
|
Instance Method Details
#exclude? ⇒ Boolean
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/ahoy/stores/active_record_token_store.rb', line 62
def exclude?
(!Ahoy.track_bots && bot?) ||
(
if Ahoy.exclude_method
warn "[DEPRECATION] Ahoy.exclude_method is deprecated - use exclude? instead"
if Ahoy.exclude_method.arity == 1
Ahoy.exclude_method.call(controller)
else
Ahoy.exclude_method.call(controller, request)
end
else
false
end
)
end
|
#track_event(name, properties, options, &block) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/ahoy/stores/active_record_token_store.rb', line 26
def track_event(name, properties, options, &block)
if self.class.uses_deprecated_subscribers?
options[:controller] ||= controller
options[:user] ||= user
options[:visit] ||= visit
options[:visit_token] ||= ahoy.visit_token
options[:visitor_token] ||= ahoy.visitor_token
subscribers = Ahoy.subscribers
if subscribers.any?
subscribers.each do |subscriber|
subscriber.track(name, properties, options.dup)
end
else
$stderr.puts "No subscribers"
end
else
event =
event_model.new do |e|
e.visit_id = visit.try(:id)
e.user = user
e.name = name
e.properties = properties
e.time = options[:time]
end
yield(event) if block_given?
event.save!
end
end
|
#track_visit(options) {|visit| ... } ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/ahoy/stores/active_record_token_store.rb', line 4
def track_visit(options, &block)
@visit =
visit_model.new do |v|
v.visit_token = ahoy.visit_token
v.visitor_token = ahoy.visitor_token
v.user = user if v.respond_to?(:user=)
v.started_at = options[:started_at] if v.respond_to?(:started_at)
v.created_at = options[:started_at] if v.respond_to?(:created_at)
end
set_visit_properties(visit)
yield(visit) if block_given?
begin
visit.save!
geocode(visit)
rescue *unique_exception_classes
end
end
|
#user ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/ahoy/stores/active_record_token_store.rb', line 78
def user
@user ||= begin
user_method = Ahoy.user_method
if user_method.respond_to?(:call)
user_method.call(controller)
elsif user_method
controller.send(user_method)
else
super
end
end
end
|
#visit ⇒ Object
58
59
60
|
# File 'lib/ahoy/stores/active_record_token_store.rb', line 58
def visit
@visit ||= visit_model.where(visit_token: ahoy.visit_token).first if ahoy.visit_token
end
|