Module: TrailGuide::Helper
- Defined in:
- lib/trail_guide/helper.rb
Defined Under Namespace
Classes: HelperProxy, MetricProxy
Instance Method Summary
collapse
Instance Method Details
#is_filtered_ip_address? ⇒ Boolean
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/trail_guide/helper.rb', line 45
def is_filtered_ip_address?
return @is_filtered_ip_address unless @is_filtered_ip_address.nil?
@is_filtered_ip_address = begin
@ip_address_filter_proc ||= -> {
return false if TrailGuide.configuration.filtered_ip_addresses.nil? || TrailGuide.configuration.filtered_ip_addresses.empty?
return false unless respond_to?(:request, true) && request.ip
TrailGuide.configuration.filtered_ip_addresses.each do |ip|
return true if ip.class == String && request.ip == ip
return true if ip.class == Regexp && request.ip =~ ip
return true if ip.class == Range && ip.first.class == IPAddr && ip.include?(IPAddr.new(request.ip))
end
return false
}
instance_exec(&@ip_address_filter_proc)
end
end
|
#is_filtered_user_agent? ⇒ Boolean
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/trail_guide/helper.rb', line 26
def is_filtered_user_agent?
return @is_filtered_user_agent unless @is_filtered_user_agent.nil?
@is_filtered_user_agent = begin
@user_agent_filter_proc ||= -> {
return false if TrailGuide.configuration.filtered_user_agents.nil? || TrailGuide.configuration.filtered_user_agents.empty?
return false unless respond_to?(:request, true) && request.user_agent
TrailGuide.configuration.filtered_user_agents.each do |ua|
return true if ua.class == String && request.user_agent == ua
return true if ua.class == Regexp && request.user_agent =~ ua
end
return false
}
instance_exec(&@user_agent_filter_proc)
end
end
|
#is_preview? ⇒ Boolean
20
21
22
23
24
|
# File 'lib/trail_guide/helper.rb', line 20
def is_preview?
return false unless respond_to?(:request, true)
= request.try(:headers)
&& ['x-purpose'] == 'preview'
end
|
#trailguide(metric = nil, **opts, &block) ⇒ Object
3
4
5
6
7
8
|
# File 'lib/trail_guide/helper.rb', line 3
def trailguide(metric=nil, **opts, &block)
@trailguide_proxy ||= HelperProxy.new(self)
@trailguide_proxy = HelperProxy.new(self) if @trailguide_proxy.context != self
return @trailguide_proxy if metric.nil?
@trailguide_proxy.choose!(metric, **opts, &block)
end
|
#trailguide_excluded_request? ⇒ Boolean
16
17
18
|
# File 'lib/trail_guide/helper.rb', line 16
def trailguide_excluded_request?
@trailguide_excluded_request ||= instance_exec(self, &TrailGuide.configuration.request_filter)
end
|
#trailguide_participant ⇒ Object
10
11
12
13
14
|
# File 'lib/trail_guide/helper.rb', line 10
def trailguide_participant
@trailguide_participant ||= TrailGuide::Participant.new(self)
@trailguide_participant = TrailGuide::Participant.new(self) if @trailguide_participant.context != self
@trailguide_participant
end
|