trailguide 0.1.21 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/trail_guide/adapters/participants/anonymous.rb +6 -7
- data/lib/trail_guide/adapters/participants/redis.rb +1 -2
- data/lib/trail_guide/experiments/participant.rb +1 -1
- data/lib/trail_guide/helper.rb +44 -41
- data/lib/trail_guide/participant.rb +35 -41
- data/lib/trail_guide/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dadd0f6c7091b171c4e9034e9e4b31b9c7300121f6ef8b75fc577dc5913cf28
|
4
|
+
data.tar.gz: 1f84fdce8ea0d73bb189732fcb5099d1e3e41e48a0fa286d7e68854cb8d038f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d53f939b8c3773cbb08f0d8d36cdec3ead6d7aa0f904d6cc7f31339bab41f388ff0ad2ae48c054429c9152dc42e049a0e6ed98bdef085f28d780bc02e0d112ed
|
7
|
+
data.tar.gz: 8a18ec65a94353dfbe557c07295bb698a5486cdfd0c2071a5ba2a5adc51fea0c3e0b671b2a5d0d108808c814c2846850d6a0d5d839f2576d64d0a8135fd47f9d
|
@@ -6,8 +6,8 @@ module TrailGuide
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
alias_method :configure, :new
|
9
|
-
def new(
|
10
|
-
configure(&block).new(
|
9
|
+
def new(_context, &block)
|
10
|
+
configure(&block).new(_context)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -18,15 +18,14 @@ module TrailGuide
|
|
18
18
|
end
|
19
19
|
|
20
20
|
# instance method, creates a new adapter and passes through config
|
21
|
-
def new(
|
22
|
-
Adapter.new(
|
21
|
+
def new(_context)
|
22
|
+
Adapter.new(configuration)
|
23
23
|
end
|
24
24
|
|
25
25
|
class Adapter
|
26
|
-
attr_reader :
|
26
|
+
attr_reader :config
|
27
27
|
|
28
|
-
def initialize(
|
29
|
-
@context = context
|
28
|
+
def initialize(config)
|
30
29
|
@config = config
|
31
30
|
end
|
32
31
|
|
data/lib/trail_guide/helper.rb
CHANGED
@@ -1,9 +1,48 @@
|
|
1
1
|
module TrailGuide
|
2
2
|
module Helper
|
3
3
|
def trailguide(metric=nil, **opts, &block)
|
4
|
-
|
5
|
-
return
|
6
|
-
|
4
|
+
@trailguide_proxy ||= HelperProxy.new(self)
|
5
|
+
return @trailguide_proxy if metric.nil?
|
6
|
+
@trailguide_proxy.choose!(metric, **opts, &block)
|
7
|
+
end
|
8
|
+
|
9
|
+
def trailguide_participant
|
10
|
+
@trailguide_participant ||= TrailGuide::Participant.new(self)
|
11
|
+
end
|
12
|
+
|
13
|
+
def trailguide_excluded_request?
|
14
|
+
@trailguide_excluded_request ||= instance_exec(self, &TrailGuide.configuration.request_filter)
|
15
|
+
end
|
16
|
+
|
17
|
+
def is_preview?
|
18
|
+
return false unless respond_to?(:request, true)
|
19
|
+
headers = request.try(:headers)
|
20
|
+
headers && headers['x-purpose'] == 'preview'
|
21
|
+
end
|
22
|
+
|
23
|
+
def is_filtered_user_agent?
|
24
|
+
return false if TrailGuide.configuration.filtered_user_agents.nil? || TrailGuide.configuration.filtered_user_agents.empty?
|
25
|
+
return false unless respond_to?(:request, true) && request.user_agent
|
26
|
+
|
27
|
+
TrailGuide.configuration.filtered_user_agents do |ua|
|
28
|
+
return true if ua.class == String && request.user_agent == ua
|
29
|
+
return true if ua.class == Regexp && request.user_agent =~ ua
|
30
|
+
end
|
31
|
+
|
32
|
+
return false
|
33
|
+
end
|
34
|
+
|
35
|
+
def is_filtered_ip_address?
|
36
|
+
return false if TrailGuide.configuration.filtered_ip_addresses.nil? || TrailGuide.configuration.filtered_ip_addresses.empty?
|
37
|
+
return false unless respond_to?(:request, true) && request.ip
|
38
|
+
|
39
|
+
TrailGuide.configuration.filtered_ip_addresses.each do |ip|
|
40
|
+
return true if ip.class == String && request.ip == ip
|
41
|
+
return true if ip.class == Regexp && request.ip =~ ip
|
42
|
+
return true if ip.class == Range && ip.first.class == IPAddr && ip.include?(IPAddr.new(request.ip))
|
43
|
+
end
|
44
|
+
|
45
|
+
return false
|
7
46
|
end
|
8
47
|
|
9
48
|
class HelperProxy
|
@@ -35,7 +74,7 @@ module TrailGuide
|
|
35
74
|
end
|
36
75
|
|
37
76
|
def participant
|
38
|
-
@participant ||=
|
77
|
+
@participant ||= context.send(:trailguide_participant)
|
39
78
|
end
|
40
79
|
|
41
80
|
def context_type
|
@@ -143,43 +182,7 @@ module TrailGuide
|
|
143
182
|
|
144
183
|
def exclude_visitor?
|
145
184
|
return false if experiment.configuration.skip_request_filter?
|
146
|
-
|
147
|
-
end
|
148
|
-
|
149
|
-
def is_preview?
|
150
|
-
return false unless context.respond_to?(:request, true)
|
151
|
-
headers = context.send(:request).try(:headers)
|
152
|
-
headers && headers['x-purpose'] == 'preview'
|
153
|
-
end
|
154
|
-
|
155
|
-
def is_filtered_user_agent?
|
156
|
-
return false if TrailGuide.configuration.filtered_user_agents.nil? || TrailGuide.configuration.filtered_user_agents.empty?
|
157
|
-
return false unless context.respond_to?(:request, true)
|
158
|
-
request = context.send(:request)
|
159
|
-
return false unless request && request.user_agent
|
160
|
-
|
161
|
-
TrailGuide.configuration.filtered_user_agents do |ua|
|
162
|
-
return true if ua.class == String && request.user_agent == ua
|
163
|
-
return true if ua.class == Regexp && request.user_agent =~ ua
|
164
|
-
end
|
165
|
-
|
166
|
-
return false
|
167
|
-
end
|
168
|
-
|
169
|
-
def is_filtered_ip_address?
|
170
|
-
return false if TrailGuide.configuration.filtered_ip_addresses.nil? || TrailGuide.configuration.filtered_ip_addresses.empty?
|
171
|
-
|
172
|
-
return false unless context.respond_to?(:request, true)
|
173
|
-
request = context.send(:request)
|
174
|
-
return false unless request && request.ip
|
175
|
-
|
176
|
-
TrailGuide.configuration.filtered_ip_addresses.each do |ip|
|
177
|
-
return true if ip.class == String && request.ip == ip
|
178
|
-
return true if ip.class == Regexp && request.ip =~ ip
|
179
|
-
return true if ip.class == Range && ip.first.class == IPAddr && ip.include?(IPAddr.new(request.ip))
|
180
|
-
end
|
181
|
-
|
182
|
-
return false
|
185
|
+
context.send(:trailguide_excluded_request?)
|
183
186
|
end
|
184
187
|
end
|
185
188
|
end
|
@@ -1,55 +1,53 @@
|
|
1
1
|
module TrailGuide
|
2
2
|
class Participant
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :adapter
|
4
4
|
delegate :key?, :keys, :[], :[]=, :delete, :destroy!, :to_h, to: :adapter
|
5
5
|
|
6
6
|
def initialize(context, adapter: nil)
|
7
|
-
@
|
8
|
-
@adapter = adapter.new(context) unless adapter.nil?
|
9
|
-
@variants = {}
|
7
|
+
@adapter = adapter.present? ? adapter.new(context) : configured_adapter.new(context)
|
10
8
|
#cleanup_inactive_experiments!
|
11
9
|
end
|
12
10
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
callback.call(config_adapter, e)
|
34
|
-
end
|
35
|
-
TrailGuide::Adapters::Participants::Anonymous.new(context)
|
11
|
+
def configured_adapter
|
12
|
+
config_adapter = TrailGuide.configuration.adapter
|
13
|
+
case config_adapter
|
14
|
+
when :cookie
|
15
|
+
config_adapter = TrailGuide::Adapters::Participants::Cookie
|
16
|
+
when :session
|
17
|
+
config_adapter = TrailGuide::Adapters::Participants::Session
|
18
|
+
when :redis
|
19
|
+
config_adapter = TrailGuide::Adapters::Participants::Redis
|
20
|
+
when :anonymous
|
21
|
+
config_adapter = TrailGuide::Adapters::Participants::Anonymous
|
22
|
+
when :multi
|
23
|
+
config_adapter = TrailGuide::Adapters::Participants::Multi
|
24
|
+
else
|
25
|
+
config_adapter = config_adapter.constantize if config_adapter.is_a?(String)
|
26
|
+
end
|
27
|
+
config_adapter
|
28
|
+
rescue => e
|
29
|
+
[TrailGuide.configuration.on_adapter_failover].flatten.compact.each do |callback|
|
30
|
+
callback.call(config_adapter, e)
|
36
31
|
end
|
32
|
+
TrailGuide::Adapters::Participants::Anonymous
|
37
33
|
end
|
38
34
|
|
39
|
-
def
|
40
|
-
return
|
41
|
-
return
|
42
|
-
return false unless adapter.key?(experiment.storage_key)
|
35
|
+
def variant(experiment)
|
36
|
+
return nil unless experiment.started?
|
37
|
+
return nil unless adapter.key?(experiment.storage_key)
|
43
38
|
varname = adapter[experiment.storage_key]
|
44
39
|
variant = experiment.variants.find { |var| var == varname }
|
45
|
-
return
|
46
|
-
return false unless variant && adapter.key?(variant.storage_key)
|
40
|
+
return nil unless variant && adapter.key?(variant.storage_key)
|
47
41
|
|
48
42
|
chosen_at = Time.at(adapter[variant.storage_key].to_i)
|
49
|
-
if chosen_at >= experiment.started_at
|
50
|
-
|
51
|
-
|
52
|
-
|
43
|
+
return variant if chosen_at >= experiment.started_at
|
44
|
+
end
|
45
|
+
|
46
|
+
def participating?(experiment, include_control=true)
|
47
|
+
var = variant(experiment)
|
48
|
+
return false if var.nil?
|
49
|
+
return false if !include_control && var.control?
|
50
|
+
return true
|
53
51
|
end
|
54
52
|
|
55
53
|
def converted?(experiment, checkpoint=nil)
|
@@ -79,10 +77,6 @@ module TrailGuide
|
|
79
77
|
end
|
80
78
|
end
|
81
79
|
|
82
|
-
def variant(experiment)
|
83
|
-
participating?(experiment) || nil
|
84
|
-
end
|
85
|
-
|
86
80
|
def participating!(variant)
|
87
81
|
adapter[variant.experiment.storage_key] = variant.name
|
88
82
|
adapter[variant.storage_key] = Time.now.to_i
|
data/lib/trail_guide/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailguide
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rebec
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|