test_track_rails_client 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +11 -8
  3. data/lib/test_track_rails_client/version.rb +1 -1
  4. data/vendor/gems/fakeable_her/fakeable_her.gemspec +22 -0
  5. data/vendor/gems/fakeable_her/lib/fakeable_her/model.rb +148 -0
  6. data/vendor/gems/fakeable_her/lib/fakeable_her/version.rb +3 -0
  7. data/vendor/gems/fakeable_her/lib/fakeable_her.rb +5 -0
  8. data/vendor/gems/her/CONTRIBUTING.md +26 -0
  9. data/vendor/gems/her/Gemfile +10 -0
  10. data/vendor/gems/her/LICENSE +7 -0
  11. data/vendor/gems/her/README.md +1023 -0
  12. data/vendor/gems/her/Rakefile +11 -0
  13. data/vendor/gems/her/UPGRADE.md +101 -0
  14. data/vendor/gems/her/gemfiles/Gemfile.activemodel-3.2.x +7 -0
  15. data/vendor/gems/her/gemfiles/Gemfile.activemodel-4.0 +7 -0
  16. data/vendor/gems/her/gemfiles/Gemfile.activemodel-4.1 +7 -0
  17. data/vendor/gems/her/gemfiles/Gemfile.activemodel-4.2 +7 -0
  18. data/vendor/gems/her/her.gemspec +31 -0
  19. data/vendor/gems/her/lib/her/api.rb +119 -0
  20. data/vendor/gems/her/lib/her/collection.rb +12 -0
  21. data/vendor/gems/her/lib/her/error_collection.rb +15 -0
  22. data/vendor/gems/her/lib/her/errors.rb +40 -0
  23. data/vendor/gems/her/lib/her/json_api/model.rb +46 -0
  24. data/vendor/gems/her/lib/her/middleware/accept_json.rb +17 -0
  25. data/vendor/gems/her/lib/her/middleware/first_level_parse_json.rb +36 -0
  26. data/vendor/gems/her/lib/her/middleware/json_api_parser.rb +36 -0
  27. data/vendor/gems/her/lib/her/middleware/parse_json.rb +21 -0
  28. data/vendor/gems/her/lib/her/middleware/second_level_parse_json.rb +36 -0
  29. data/vendor/gems/her/lib/her/middleware.rb +12 -0
  30. data/vendor/gems/her/lib/her/model/active_model_overrides.rb +13 -0
  31. data/vendor/gems/her/lib/her/model/associations/association.rb +106 -0
  32. data/vendor/gems/her/lib/her/model/associations/association_proxy.rb +46 -0
  33. data/vendor/gems/her/lib/her/model/associations/belongs_to_association.rb +96 -0
  34. data/vendor/gems/her/lib/her/model/associations/has_many_association.rb +100 -0
  35. data/vendor/gems/her/lib/her/model/associations/has_one_association.rb +79 -0
  36. data/vendor/gems/her/lib/her/model/associations.rb +141 -0
  37. data/vendor/gems/her/lib/her/model/attributes.rb +304 -0
  38. data/vendor/gems/her/lib/her/model/base.rb +33 -0
  39. data/vendor/gems/her/lib/her/model/deprecated_methods.rb +61 -0
  40. data/vendor/gems/her/lib/her/model/http.rb +117 -0
  41. data/vendor/gems/her/lib/her/model/introspection.rb +65 -0
  42. data/vendor/gems/her/lib/her/model/nested_attributes.rb +45 -0
  43. data/vendor/gems/her/lib/her/model/orm.rb +219 -0
  44. data/vendor/gems/her/lib/her/model/parse.rb +215 -0
  45. data/vendor/gems/her/lib/her/model/paths.rb +126 -0
  46. data/vendor/gems/her/lib/her/model/relation.rb +251 -0
  47. data/vendor/gems/her/lib/her/model.rb +81 -0
  48. data/vendor/gems/her/lib/her/version.rb +3 -0
  49. data/vendor/gems/her/lib/her.rb +20 -0
  50. data/vendor/gems/her/spec/api_spec.rb +114 -0
  51. data/vendor/gems/her/spec/collection_spec.rb +26 -0
  52. data/vendor/gems/her/spec/error_collection_spec.rb +33 -0
  53. data/vendor/gems/her/spec/json_api/model_spec.rb +168 -0
  54. data/vendor/gems/her/spec/middleware/accept_json_spec.rb +10 -0
  55. data/vendor/gems/her/spec/middleware/first_level_parse_json_spec.rb +62 -0
  56. data/vendor/gems/her/spec/middleware/json_api_parser_spec.rb +32 -0
  57. data/vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb +35 -0
  58. data/vendor/gems/her/spec/model/associations/association_proxy_spec.rb +31 -0
  59. data/vendor/gems/her/spec/model/associations_spec.rb +504 -0
  60. data/vendor/gems/her/spec/model/attributes_spec.rb +404 -0
  61. data/vendor/gems/her/spec/model/callbacks_spec.rb +145 -0
  62. data/vendor/gems/her/spec/model/dirty_spec.rb +110 -0
  63. data/vendor/gems/her/spec/model/http_spec.rb +165 -0
  64. data/vendor/gems/her/spec/model/introspection_spec.rb +76 -0
  65. data/vendor/gems/her/spec/model/nested_attributes_spec.rb +134 -0
  66. data/vendor/gems/her/spec/model/orm_spec.rb +791 -0
  67. data/vendor/gems/her/spec/model/parse_spec.rb +372 -0
  68. data/vendor/gems/her/spec/model/paths_spec.rb +347 -0
  69. data/vendor/gems/her/spec/model/relation_spec.rb +226 -0
  70. data/vendor/gems/her/spec/model/validations_spec.rb +42 -0
  71. data/vendor/gems/her/spec/model_spec.rb +31 -0
  72. data/vendor/gems/her/spec/spec_helper.rb +27 -0
  73. data/vendor/gems/her/spec/support/extensions/array.rb +5 -0
  74. data/vendor/gems/her/spec/support/extensions/hash.rb +5 -0
  75. data/vendor/gems/her/spec/support/macros/her_macros.rb +17 -0
  76. data/vendor/gems/her/spec/support/macros/model_macros.rb +36 -0
  77. data/vendor/gems/her/spec/support/macros/request_macros.rb +27 -0
  78. data/vendor/gems/publicsuffix-ruby/CHANGELOG.md +236 -0
  79. data/vendor/gems/publicsuffix-ruby/Gemfile +3 -0
  80. data/vendor/gems/publicsuffix-ruby/LICENSE.txt +22 -0
  81. data/vendor/gems/publicsuffix-ruby/README.md +151 -0
  82. data/vendor/gems/publicsuffix-ruby/Rakefile +109 -0
  83. data/vendor/gems/publicsuffix-ruby/lib/definitions.txt +11467 -0
  84. data/vendor/gems/publicsuffix-ruby/lib/public_suffix/domain.rb +387 -0
  85. data/vendor/gems/publicsuffix-ruby/lib/public_suffix/errors.rb +53 -0
  86. data/vendor/gems/publicsuffix-ruby/lib/public_suffix/list.rb +302 -0
  87. data/vendor/gems/publicsuffix-ruby/lib/public_suffix/rule.rb +373 -0
  88. data/vendor/gems/publicsuffix-ruby/lib/public_suffix/version.rb +23 -0
  89. data/vendor/gems/publicsuffix-ruby/lib/public_suffix.rb +131 -0
  90. data/vendor/gems/publicsuffix-ruby/public_suffix.gemspec +39 -0
  91. data/vendor/gems/publicsuffix-ruby/test/acceptance_test.rb +42 -0
  92. data/vendor/gems/publicsuffix-ruby/test/test_helper.rb +6 -0
  93. data/vendor/gems/publicsuffix-ruby/test/unit/domain_test.rb +170 -0
  94. data/vendor/gems/publicsuffix-ruby/test/unit/errors_test.rb +23 -0
  95. data/vendor/gems/publicsuffix-ruby/test/unit/list_test.rb +179 -0
  96. data/vendor/gems/publicsuffix-ruby/test/unit/public_suffix_test.rb +115 -0
  97. data/vendor/gems/publicsuffix-ruby/test/unit/rule_test.rb +307 -0
  98. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/capybara_configuration.rb +98 -0
  99. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/matchers.rb +151 -0
  100. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rspec_configuration.rb +34 -0
  101. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rubocop/cop/betterment/html_safe.rb +15 -0
  102. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rubocop/cop/betterment/raw.rb +15 -0
  103. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rubocop/cop/betterment/safe_concat.rb +15 -0
  104. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rubocop.rb +3 -0
  105. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/shared_examples/betterment_application_examples.rb +47 -0
  106. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/shared_examples.rb +1 -0
  107. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/site_prism_configuration.rb +42 -0
  108. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/site_prism_dropdown.rb +17 -0
  109. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/version.rb +3 -0
  110. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/webmock_configuration.rb +8 -0
  111. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers.rb +2 -0
  112. data/vendor/gems/ruby_spec_helpers/ruby_spec_helpers.gemspec +25 -0
  113. metadata +110 -1
@@ -0,0 +1,302 @@
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
@@ -0,0 +1,373 @@
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
@@ -0,0 +1,23 @@
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