test_track_rails_client 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +62 -7
  3. data/Rakefile +8 -4
  4. data/app/models/test_track/analytics/mixpanel_client.rb +2 -5
  5. data/app/models/test_track/analytics/safe_wrapper.rb +4 -4
  6. data/app/models/test_track/config_updater.rb +2 -2
  7. data/app/models/test_track/fake/split_registry.rb +2 -2
  8. data/app/models/test_track/notify_assignment_job.rb +3 -4
  9. data/app/models/test_track/offline_session.rb +6 -4
  10. data/app/models/test_track/remote/split_registry.rb +2 -2
  11. data/app/models/test_track/remote/visitor.rb +2 -2
  12. data/app/models/test_track/session.rb +12 -73
  13. data/app/models/test_track/unsynced_assignments_notifier.rb +2 -4
  14. data/app/models/test_track/vary_dsl.rb +5 -1
  15. data/app/models/test_track/visitor.rb +0 -11
  16. data/lib/test_track_rails_client/version.rb +1 -1
  17. data/vendor/gems/fakeable_her/fakeable_her.gemspec +2 -3
  18. data/vendor/gems/her/her.gemspec +4 -5
  19. data/vendor/gems/her/lib/her/api.rb +1 -1
  20. data/vendor/gems/her/lib/her/model/associations/association_proxy.rb +1 -2
  21. data/vendor/gems/her/lib/her/model/orm.rb +41 -29
  22. data/vendor/gems/her/lib/her/model/parse.rb +1 -0
  23. data/vendor/gems/her/lib/her/model/relation.rb +21 -6
  24. data/vendor/gems/her/lib/her/version.rb +1 -1
  25. metadata +52 -139
  26. data/app/models/test_track/create_alias_job.rb +0 -18
  27. data/vendor/gems/her/CONTRIBUTING.md +0 -26
  28. data/vendor/gems/her/Gemfile +0 -10
  29. data/vendor/gems/her/README.md +0 -1023
  30. data/vendor/gems/her/Rakefile +0 -11
  31. data/vendor/gems/her/UPGRADE.md +0 -101
  32. data/vendor/gems/her/gemfiles/Gemfile.activemodel-3.2.x +0 -7
  33. data/vendor/gems/her/gemfiles/Gemfile.activemodel-4.0 +0 -7
  34. data/vendor/gems/her/gemfiles/Gemfile.activemodel-4.1 +0 -7
  35. data/vendor/gems/her/gemfiles/Gemfile.activemodel-4.2 +0 -7
  36. data/vendor/gems/her/spec/api_spec.rb +0 -114
  37. data/vendor/gems/her/spec/collection_spec.rb +0 -26
  38. data/vendor/gems/her/spec/error_collection_spec.rb +0 -33
  39. data/vendor/gems/her/spec/json_api/model_spec.rb +0 -168
  40. data/vendor/gems/her/spec/middleware/accept_json_spec.rb +0 -10
  41. data/vendor/gems/her/spec/middleware/first_level_parse_json_spec.rb +0 -62
  42. data/vendor/gems/her/spec/middleware/json_api_parser_spec.rb +0 -32
  43. data/vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb +0 -35
  44. data/vendor/gems/her/spec/model/associations/association_proxy_spec.rb +0 -31
  45. data/vendor/gems/her/spec/model/associations_spec.rb +0 -504
  46. data/vendor/gems/her/spec/model/attributes_spec.rb +0 -404
  47. data/vendor/gems/her/spec/model/callbacks_spec.rb +0 -145
  48. data/vendor/gems/her/spec/model/dirty_spec.rb +0 -110
  49. data/vendor/gems/her/spec/model/http_spec.rb +0 -165
  50. data/vendor/gems/her/spec/model/introspection_spec.rb +0 -76
  51. data/vendor/gems/her/spec/model/nested_attributes_spec.rb +0 -134
  52. data/vendor/gems/her/spec/model/orm_spec.rb +0 -791
  53. data/vendor/gems/her/spec/model/parse_spec.rb +0 -372
  54. data/vendor/gems/her/spec/model/paths_spec.rb +0 -347
  55. data/vendor/gems/her/spec/model/relation_spec.rb +0 -226
  56. data/vendor/gems/her/spec/model/validations_spec.rb +0 -42
  57. data/vendor/gems/her/spec/model_spec.rb +0 -31
  58. data/vendor/gems/her/spec/spec_helper.rb +0 -27
  59. data/vendor/gems/her/spec/support/extensions/array.rb +0 -5
  60. data/vendor/gems/her/spec/support/extensions/hash.rb +0 -5
  61. data/vendor/gems/her/spec/support/macros/her_macros.rb +0 -17
  62. data/vendor/gems/her/spec/support/macros/model_macros.rb +0 -36
  63. data/vendor/gems/her/spec/support/macros/request_macros.rb +0 -27
  64. data/vendor/gems/publicsuffix-ruby/CHANGELOG.md +0 -236
  65. data/vendor/gems/publicsuffix-ruby/Gemfile +0 -3
  66. data/vendor/gems/publicsuffix-ruby/LICENSE.txt +0 -22
  67. data/vendor/gems/publicsuffix-ruby/README.md +0 -151
  68. data/vendor/gems/publicsuffix-ruby/Rakefile +0 -109
  69. data/vendor/gems/publicsuffix-ruby/lib/definitions.txt +0 -11467
  70. data/vendor/gems/publicsuffix-ruby/lib/public_suffix/domain.rb +0 -387
  71. data/vendor/gems/publicsuffix-ruby/lib/public_suffix/errors.rb +0 -53
  72. data/vendor/gems/publicsuffix-ruby/lib/public_suffix/list.rb +0 -302
  73. data/vendor/gems/publicsuffix-ruby/lib/public_suffix/rule.rb +0 -373
  74. data/vendor/gems/publicsuffix-ruby/lib/public_suffix/version.rb +0 -23
  75. data/vendor/gems/publicsuffix-ruby/lib/public_suffix.rb +0 -131
  76. data/vendor/gems/publicsuffix-ruby/public_suffix.gemspec +0 -39
  77. data/vendor/gems/publicsuffix-ruby/test/acceptance_test.rb +0 -42
  78. data/vendor/gems/publicsuffix-ruby/test/test_helper.rb +0 -6
  79. data/vendor/gems/publicsuffix-ruby/test/unit/domain_test.rb +0 -170
  80. data/vendor/gems/publicsuffix-ruby/test/unit/errors_test.rb +0 -23
  81. data/vendor/gems/publicsuffix-ruby/test/unit/list_test.rb +0 -179
  82. data/vendor/gems/publicsuffix-ruby/test/unit/public_suffix_test.rb +0 -115
  83. data/vendor/gems/publicsuffix-ruby/test/unit/rule_test.rb +0 -307
  84. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/capybara_configuration.rb +0 -98
  85. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/matchers.rb +0 -151
  86. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rspec_configuration.rb +0 -34
  87. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rubocop/cop/betterment/html_safe.rb +0 -15
  88. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rubocop/cop/betterment/raw.rb +0 -15
  89. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rubocop/cop/betterment/safe_concat.rb +0 -15
  90. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rubocop.rb +0 -3
  91. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/shared_examples/betterment_application_examples.rb +0 -43
  92. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/shared_examples.rb +0 -1
  93. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/site_prism_configuration.rb +0 -42
  94. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/site_prism_dropdown.rb +0 -17
  95. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/version.rb +0 -3
  96. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/webmock_configuration.rb +0 -8
  97. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers.rb +0 -2
  98. data/vendor/gems/ruby_spec_helpers/ruby_spec_helpers.gemspec +0 -25
@@ -1,302 +0,0 @@
1
- #--
2
- # Public Suffix
3
- #
4
- # Domain name parser based on the Public Suffix List.
5
- #
6
- # Copyright (c) 2009-2014 Simone Carletti <weppos@weppos.net>
7
- #++
8
-
9
-
10
- module PublicSuffix
11
-
12
- # A {PublicSuffix::List} is a collection of one
13
- # or more {PublicSuffix::Rule}.
14
- #
15
- # Given a {PublicSuffix::List},
16
- # you can add or remove {PublicSuffix::Rule},
17
- # iterate all items in the list or search for the first rule
18
- # which matches a specific domain name.
19
- #
20
- # # Create a new list
21
- # list = PublicSuffix::List.new
22
- #
23
- # # Push two rules to the list
24
- # list << PublicSuffix::Rule.factory("it")
25
- # list << PublicSuffix::Rule.factory("com")
26
- #
27
- # # Get the size of the list
28
- # list.size
29
- # # => 2
30
- #
31
- # # Search for the rule matching given domain
32
- # list.find("example.com")
33
- # # => #<PublicSuffix::Rule::Normal>
34
- # list.find("example.org")
35
- # # => nil
36
- #
37
- # You can create as many {PublicSuffix::List} you want.
38
- # The {PublicSuffix::List.default} rule list is used
39
- # to tokenize and validate a domain.
40
- #
41
- # {PublicSuffix::List} implements +Enumerable+ module.
42
- #
43
- class List
44
- include Enumerable
45
-
46
- class << self
47
- attr_accessor :default
48
- attr_accessor :default_definition
49
- end
50
-
51
- # Gets the default rule list.
52
- # Initializes a new {PublicSuffix::List} parsing the content
53
- # of {PublicSuffix::List.default_definition}, if required.
54
- #
55
- # @return [PublicSuffix::List]
56
- def self.default
57
- @default ||= parse(default_definition)
58
- end
59
-
60
- # Sets the default rule list to +value+.
61
- #
62
- # @param [PublicSuffix::List] value
63
- # The new rule list.
64
- #
65
- # @return [PublicSuffix::List]
66
- def self.default=(value)
67
- @default = value
68
- end
69
-
70
- # Shows if support for private (non-ICANN) domains is enabled or not
71
- #
72
- # @return [Boolean]
73
- def self.private_domains?
74
- @private_domains != false
75
- end
76
-
77
- # Enables/disables support for private (non-ICANN) domains
78
- # Implicitly reloads the list
79
- # @param [Boolean] enable/disable support
80
- #
81
- # @return [PublicSuffix::List]
82
- def self.private_domains=(value)
83
- @private_domains = !!value
84
- self.clear
85
- end
86
-
87
- # Sets the default rule list to +nil+.
88
- #
89
- # @return [self]
90
- def self.clear
91
- self.default = nil
92
- self
93
- end
94
-
95
- # Resets the default rule list and reinitialize it
96
- # parsing the content of {PublicSuffix::List.default_definition}.
97
- #
98
- # @return [PublicSuffix::List]
99
- def self.reload
100
- self.clear.default
101
- end
102
-
103
- # Gets the default definition list.
104
- # Can be any <tt>IOStream</tt> including a <tt>File</tt>
105
- # or a simple <tt>String</tt>.
106
- # The object must respond to <tt>#each_line</tt>.
107
- #
108
- # @return [File]
109
- def self.default_definition
110
- @default_definition || File.new(File.join(File.dirname(__FILE__), "..", "definitions.txt"), "r:utf-8")
111
- end
112
-
113
- # Parse given +input+ treating the content as Public Suffix List.
114
- #
115
- # See http://publicsuffix.org/format/ for more details about input format.
116
- #
117
- # @param [String] input The rule list to parse.
118
- #
119
- # @return [Array<PublicSuffix::Rule::*>]
120
- def self.parse(input)
121
- new do |list|
122
- input.each_line do |line|
123
- line.strip!
124
- break if !private_domains? && line.include?('===BEGIN PRIVATE DOMAINS===')
125
- # strip blank lines
126
- if line.empty?
127
- next
128
- # strip comments
129
- elsif line =~ %r{^//}
130
- next
131
- # append rule
132
- else
133
- list.add(Rule.factory(line), false)
134
- end
135
- end
136
- end
137
- end
138
-
139
-
140
- # Gets the array of rules.
141
- #
142
- # @return [Array<PublicSuffix::Rule::*>]
143
- attr_reader :rules
144
-
145
- # Gets the naive index, a hash that with the keys being the first label of
146
- # every rule pointing to an array of integers (indexes of the rules in @rules).
147
- #
148
- # @return [Array]
149
- attr_reader :indexes
150
-
151
-
152
- # Initializes an empty {PublicSuffix::List}.
153
- #
154
- # @yield [self] Yields on self.
155
- # @yieldparam [PublicSuffix::List] self The newly created instance.
156
- #
157
- def initialize(&block)
158
- @rules = []
159
- @indexes = {}
160
- yield(self) if block_given?
161
- create_index!
162
- end
163
-
164
- # Creates a naive index for +@rules+. Just a hash that will tell
165
- # us where the elements of +@rules+ are relative to its first
166
- # {PublicSuffix::Rule::Base#labels} element.
167
- #
168
- # For instance if @rules[5] and @rules[4] are the only elements of the list
169
- # where Rule#labels.first is 'us' @indexes['us'] #=> [5,4], that way in
170
- # select we can avoid mapping every single rule against the candidate domain.
171
- def create_index!
172
- @rules.map { |l| l.labels.first }.each_with_index do |elm, inx|
173
- if !@indexes.has_key?(elm)
174
- @indexes[elm] = [inx]
175
- else
176
- @indexes[elm] << inx
177
- end
178
- end
179
- end
180
-
181
- # Checks whether two lists are equal.
182
- #
183
- # List <tt>one</tt> is equal to <tt>two</tt>, if <tt>two</tt> is an instance of
184
- # {PublicSuffix::List} and each +PublicSuffix::Rule::*+
185
- # in list <tt>one</tt> is available in list <tt>two</tt>, in the same order.
186
- #
187
- # @param [PublicSuffix::List] other
188
- # The List to compare.
189
- #
190
- # @return [Boolean]
191
- def ==(other)
192
- return false unless other.is_a?(List)
193
- self.equal?(other) ||
194
- self.rules == other.rules
195
- end
196
- alias :eql? :==
197
-
198
- # Iterates each rule in the list.
199
- def each(*args, &block)
200
- @rules.each(*args, &block)
201
- end
202
-
203
- # Gets the list as array.
204
- #
205
- # @return [Array<PublicSuffix::Rule::*>]
206
- def to_a
207
- @rules
208
- end
209
-
210
- # Adds the given object to the list
211
- # and optionally refreshes the rule index.
212
- #
213
- # @param [PublicSuffix::Rule::*] rule
214
- # The rule to add to the list.
215
- # @param [Boolean] index
216
- # Set to true to recreate the rule index
217
- # after the rule has been added to the list.
218
- #
219
- # @return [self]
220
- #
221
- # @see #create_index!
222
- #
223
- def add(rule, index = true)
224
- @rules << rule
225
- create_index! if index == true
226
- self
227
- end
228
- alias << add
229
-
230
- # Gets the number of elements in the list.
231
- #
232
- # @return [Integer]
233
- def size
234
- @rules.size
235
- end
236
- alias length size
237
-
238
- # Checks whether the list is empty.
239
- #
240
- # @return [Boolean]
241
- def empty?
242
- @rules.empty?
243
- end
244
-
245
- # Removes all elements.
246
- #
247
- # @return [self]
248
- def clear
249
- @rules.clear
250
- self
251
- end
252
-
253
-
254
- # Returns the most appropriate rule for domain.
255
- #
256
- # From the Public Suffix List documentation:
257
- #
258
- # * If a hostname matches more than one rule in the file,
259
- # the longest matching rule (the one with the most levels) will be used.
260
- # * An exclamation mark (!) at the start of a rule marks an exception to a previous wildcard rule.
261
- # An exception rule takes priority over any other matching rule.
262
- #
263
- # == Algorithm description
264
- #
265
- # * Match domain against all rules and take note of the matching ones.
266
- # * If no rules match, the prevailing rule is "*".
267
- # * If more than one rule matches, the prevailing rule is the one which is an exception rule.
268
- # * If there is no matching exception rule, the prevailing rule is the one with the most labels.
269
- # * If the prevailing rule is a exception rule, modify it by removing the leftmost label.
270
- # * The public suffix is the set of labels from the domain
271
- # which directly match the labels of the prevailing rule (joined by dots).
272
- # * The registered domain is the public suffix plus one additional label.
273
- #
274
- # @param [String, #to_s] domain The domain name.
275
- #
276
- # @return [PublicSuffix::Rule::*, nil]
277
- def find(domain)
278
- rules = select(domain)
279
- rules.select { |r| r.type == :exception }.first ||
280
- rules.inject { |t,r| t.length > r.length ? t : r }
281
- end
282
-
283
- # Selects all the rules matching given domain.
284
- #
285
- # Will use +@indexes+ to try only the rules that share the same first label,
286
- # that will speed up things when using +List.find('foo')+ a lot.
287
- #
288
- # @param [String, #to_s] domain The domain name.
289
- #
290
- # @return [Array<PublicSuffix::Rule::*>]
291
- def select(domain)
292
- # raise DomainInvalid, "Blank domain"
293
- return [] if domain.to_s !~ /[^[:space:]]/
294
- # raise DomainInvalid, "`#{domain}' is not expected to contain a scheme"
295
- return [] if domain.include?("://")
296
-
297
- indices = (@indexes[Domain.domain_to_labels(domain).first] || [])
298
- @rules.values_at(*indices).select { |rule| rule.match?(domain) }
299
- end
300
-
301
- end
302
- end
@@ -1,373 +0,0 @@
1
- #--
2
- # Public Suffix
3
- #
4
- # Domain name parser based on the Public Suffix List.
5
- #
6
- # Copyright (c) 2009-2014 Simone Carletti <weppos@weppos.net>
7
- #++
8
-
9
-
10
- module PublicSuffix
11
-
12
- # A Rule is a special object which holds a single definition
13
- # of the Public Suffix List.
14
- #
15
- # There are 3 types of ruleas, each one represented by a specific
16
- # subclass within the +PublicSuffix::Rule+ namespace.
17
- #
18
- # To create a new Rule, use the {PublicSuffix::Rule#factory} method.
19
- #
20
- # PublicSuffix::Rule.factory("ar")
21
- # # => #<PublicSuffix::Rule::Normal>
22
- #
23
- class Rule
24
-
25
- # Takes the +name+ of the rule, detects the specific rule class
26
- # and creates a new instance of that class.
27
- # The +name+ becomes the rule +value+.
28
- #
29
- # @param [String] name The rule definition.
30
- #
31
- # @return [PublicSuffix::Rule::*] A rule instance.
32
- #
33
- # @example Creates a Normal rule
34
- # PublicSuffix::Rule.factory("ar")
35
- # # => #<PublicSuffix::Rule::Normal>
36
- #
37
- # @example Creates a Wildcard rule
38
- # PublicSuffix::Rule.factory("*.ar")
39
- # # => #<PublicSuffix::Rule::Wildcard>
40
- #
41
- # @example Creates an Exception rule
42
- # PublicSuffix::Rule.factory("!congresodelalengua3.ar")
43
- # # => #<PublicSuffix::Rule::Exception>
44
- #
45
- def self.factory(name)
46
- klass = case name.to_s[0..0]
47
- when "*" then "wildcard"
48
- when "!" then "exception"
49
- else "normal"
50
- end
51
- const_get(klass.capitalize).new(name)
52
- end
53
-
54
-
55
- #
56
- # = Abstract rule class
57
- #
58
- # This represent the base class for a Rule definition
59
- # in the {Public Suffix List}[http://publicsuffix.org].
60
- #
61
- # This is intended to be an Abstract class
62
- # and you shouldn't create a direct instance. The only purpose
63
- # of this class is to expose a common interface
64
- # for all the available subclasses.
65
- #
66
- # * {PublicSuffix::Rule::Normal}
67
- # * {PublicSuffix::Rule::Exception}
68
- # * {PublicSuffix::Rule::Wildcard}
69
- #
70
- # == Properties
71
- #
72
- # A rule is composed by 4 properties:
73
- #
74
- # name - The name of the rule, corresponding to the rule definition
75
- # in the public suffix list
76
- # value - The value, a normalized version of the rule name.
77
- # The normalization process depends on rule tpe.
78
- # type - The rule type (:normal, :wildcard, :exception)
79
- # labels - The canonicalized rule name
80
- #
81
- # Here's an example
82
- #
83
- # PublicSuffix::Rule.factory("*.google.com")
84
- # #<PublicSuffix::Rule::Wildcard:0x1015c14b0
85
- # @labels=["com", "google"],
86
- # @name="*.google.com",
87
- # @type=:wildcard,
88
- # @value="google.com"
89
- # >
90
- #
91
- # == Rule Creation
92
- #
93
- # The best way to create a new rule is passing the rule name
94
- # to the <tt>PublicSuffix::Rule.factory</tt> method.
95
- #
96
- # PublicSuffix::Rule.factory("com")
97
- # # => PublicSuffix::Rule::Normal
98
- #
99
- # PublicSuffix::Rule.factory("*.com")
100
- # # => PublicSuffix::Rule::Wildcard
101
- #
102
- # This method will detect the rule type and create an instance
103
- # from the proper rule class.
104
- #
105
- # == Rule Usage
106
- #
107
- # A rule describes the composition of a domain name
108
- # and explains how to tokenize the domain name
109
- # into tld, sld and trd.
110
- #
111
- # To use a rule, you first need to be sure the domain you want to tokenize
112
- # can be handled by the current rule.
113
- # You can use the <tt>#match?</tt> method.
114
- #
115
- # rule = PublicSuffix::Rule.factory("com")
116
- #
117
- # rule.match?("google.com")
118
- # # => true
119
- #
120
- # rule.match?("google.com")
121
- # # => false
122
- #
123
- # Rule order is significant. A domain can match more than one rule.
124
- # See the {Public Suffix Documentation}[http://publicsuffix.org/format/]
125
- # to learn more about rule priority.
126
- #
127
- # When you have the right rule, you can use it to tokenize the domain name.
128
- #
129
- # rule = PublicSuffix::Rule.factory("com")
130
- #
131
- # rule.decompose("google.com")
132
- # # => ["google", "com"]
133
- #
134
- # rule.decompose("www.google.com")
135
- # # => ["www.google", "com"]
136
- #
137
- # @abstract
138
- #
139
- class Base
140
-
141
- attr_reader :name, :value, :type, :labels
142
-
143
- # Initializes a new rule with name and value.
144
- # If value is +nil+, name also becomes the value for this rule.
145
- #
146
- # @param [String] name
147
- # The name of the rule
148
- # @param [String] value
149
- # The value of the rule. If nil, defaults to +name+.
150
- #
151
- def initialize(name, value = nil)
152
- @name = name.to_s
153
- @value = value || @name
154
- @type = self.class.name.split("::").last.downcase.to_sym
155
- @labels = Domain.domain_to_labels(@value)
156
- end
157
-
158
- # Checks whether this rule is equal to <tt>other</tt>.
159
- #
160
- # @param [PublicSuffix::Rule::*] other
161
- # The rule to compare.
162
- #
163
- # @return [Boolean]
164
- # Returns true if this rule and other are instances of the same class
165
- # and has the same value, false otherwise.
166
- def ==(other)
167
- return false unless other.is_a?(self.class)
168
- self.equal?(other) ||
169
- self.name == other.name
170
- end
171
- alias :eql? :==
172
-
173
-
174
- # Checks if this rule matches +domain+.
175
- #
176
- # @param [String, #to_s] domain
177
- # The domain name to check.
178
- #
179
- # @return [Boolean]
180
- #
181
- # @example
182
- # rule = Rule.factory("com")
183
- # # #<PublicSuffix::Rule::Normal>
184
- # rule.match?("example.com")
185
- # # => true
186
- # rule.match?("example.net")
187
- # # => false
188
- #
189
- def match?(domain)
190
- l1 = labels
191
- l2 = Domain.domain_to_labels(domain)
192
- odiff(l1, l2).empty?
193
- end
194
-
195
- # Checks if this rule allows +domain+.
196
- #
197
- # @param [String, #to_s] domain
198
- # The domain name to check.
199
- #
200
- # @return [Boolean]
201
- #
202
- # @example
203
- # rule = Rule.factory("*.do")
204
- # # => #<PublicSuffix::Rule::Wildcard>
205
- # rule.allow?("example.do")
206
- # # => false
207
- # rule.allow?("www.example.do")
208
- # # => true
209
- #
210
- def allow?(domain)
211
- !decompose(domain).last.nil?
212
- end
213
-
214
-
215
- # Gets the length of this rule for comparison.
216
- # The length usually matches the number of rule +parts+.
217
- #
218
- # Subclasses might actually override this method.
219
- #
220
- # @return [Integer] The number of parts.
221
- def length
222
- parts.length
223
- end
224
-
225
- #
226
- # @raise [NotImplementedError]
227
- # @abstract
228
- def parts
229
- raise NotImplementedError
230
- end
231
-
232
- #
233
- # @param [String, #to_s] domain
234
- # The domain name to decompose.
235
- #
236
- # @return [Array<String, nil>]
237
- #
238
- # @raise [NotImplementedError]
239
- # @abstract
240
- def decompose(domain)
241
- raise NotImplementedError
242
- end
243
-
244
-
245
- private
246
-
247
- def odiff(one, two)
248
- ii = 0
249
- while(ii < one.size && one[ii] == two[ii])
250
- ii += 1
251
- end
252
- one[ii..one.length]
253
- end
254
-
255
- end
256
-
257
- class Normal < Base
258
-
259
- # Initializes a new rule with +name+.
260
- #
261
- # @param [String] name
262
- # The name of this rule.
263
- #
264
- def initialize(name)
265
- super(name, name)
266
- end
267
-
268
- # dot-split rule value and returns all rule parts
269
- # in the order they appear in the value.
270
- #
271
- # @return [Array<String>]
272
- def parts
273
- @parts ||= @value.split(".")
274
- end
275
-
276
- # Decomposes the domain according to rule properties.
277
- #
278
- # @param [String, #to_s] domain
279
- # The domain name to decompose.
280
- #
281
- # @return [Array<String>]
282
- # The array with [trd + sld, tld].
283
- #
284
- def decompose(domain)
285
- domain.to_s.chomp(".") =~ /^(.*)\.(#{parts.join('\.')})$/
286
- [$1, $2]
287
- end
288
-
289
- end
290
-
291
- class Wildcard < Base
292
-
293
- # Initializes a new rule with +name+.
294
- #
295
- # @param [String] name
296
- # The name of this rule.
297
- #
298
- def initialize(name)
299
- super(name, name.to_s[2..-1])
300
- end
301
-
302
- # dot-split rule value and returns all rule parts
303
- # in the order they appear in the value.
304
- #
305
- # @return [Array<String>]
306
- def parts
307
- @parts ||= @value.split(".")
308
- end
309
-
310
- # Overwrites the default implementation to cope with
311
- # the +*+ char.
312
- #
313
- # @return [Integer] The number of parts.
314
- def length
315
- parts.length + 1 # * counts as 1
316
- end
317
-
318
- # Decomposes the domain according to rule properties.
319
- #
320
- # @param [String, #to_s] domain
321
- # The domain name to decompose.
322
- #
323
- # @return [Array<String>]
324
- # The array with [trd + sld, tld].
325
- #
326
- def decompose(domain)
327
- domain.to_s.chomp(".") =~ /^(.*)\.(.*?\.#{parts.join('\.')})$/
328
- [$1, $2]
329
- end
330
-
331
- end
332
-
333
- class Exception < Base
334
-
335
- # Initializes a new rule with +name+.
336
- #
337
- # @param [String] name The name of this rule.
338
- #
339
- def initialize(name)
340
- super(name, name.to_s[1..-1])
341
- end
342
-
343
- # dot-split rule value and returns all rule parts
344
- # in the order they appear in the value.
345
- # The leftmost label is not considered a label.
346
- #
347
- # See http://publicsuffix.org/format/:
348
- # If the prevailing rule is a exception rule,
349
- # modify it by removing the leftmost label.
350
- #
351
- # @return [Array<String>]
352
- def parts
353
- @parts ||= @value.split(".")[1..-1]
354
- end
355
-
356
- # Decomposes the domain according to rule properties.
357
- #
358
- # @param [String, #to_s] domain
359
- # The domain name to decompose.
360
- #
361
- # @return [Array<String>]
362
- # The array with [trd + sld, tld].
363
- #
364
- def decompose(domain)
365
- domain.to_s.chomp(".") =~ /^(.*)\.(#{parts.join('\.')})$/
366
- [$1, $2]
367
- end
368
-
369
- end
370
-
371
- end
372
-
373
- end
@@ -1,23 +0,0 @@
1
- #--
2
- # Public Suffix
3
- #
4
- # Domain name parser based on the Public Suffix List.
5
- #
6
- # Copyright (c) 2009-2014 Simone Carletti <weppos@weppos.net>
7
- #++
8
-
9
-
10
- module PublicSuffix
11
-
12
- module Version
13
- MAJOR = 1
14
- MINOR = 4
15
- PATCH = 6
16
- BUILD = nil
17
-
18
- STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join(".")
19
- end
20
-
21
- VERSION = Version::STRING
22
-
23
- end