public_suffix 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,6 +43,83 @@ module PublicSuffix
43
43
  class List
44
44
  include Enumerable
45
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
+ # Sets the default rule list to +nil+.
71
+ #
72
+ # @return [self]
73
+ def self.clear
74
+ self.default = nil
75
+ self
76
+ end
77
+
78
+ # Resets the default rule list and reinitialize it
79
+ # parsing the content of {PublicSuffix::List.default_definition}.
80
+ #
81
+ # @return [PublicSuffix::List]
82
+ def self.reload
83
+ self.clear.default
84
+ end
85
+
86
+ # Gets the default definition list.
87
+ # Can be any <tt>IOStream</tt> including a <tt>File</tt>
88
+ # or a simple <tt>String</tt>.
89
+ # The object must respond to <tt>#each_line</tt>.
90
+ #
91
+ # @return [File]
92
+ def self.default_definition
93
+ @default_definition || File.new(File.join(File.dirname(__FILE__), "definitions.txt"), "r:utf-8")
94
+ end
95
+
96
+ # Parse given +input+ treating the content as Public Suffix List.
97
+ #
98
+ # See http://publicsuffix.org/format/ for more details about input format.
99
+ #
100
+ # @param [String] input The rule list to parse.
101
+ #
102
+ # @return [Array<PublicSuffix::Rule::*>]
103
+ def self.parse(input)
104
+ new do |list|
105
+ input.each_line do |line|
106
+ line.strip!
107
+
108
+ # strip blank lines
109
+ if line.empty?
110
+ next
111
+ # strip comments
112
+ elsif line =~ %r{^//}
113
+ next
114
+ # append rule
115
+ else
116
+ list.add(Rule.factory(line), false)
117
+ end
118
+ end
119
+ end
120
+ end
121
+
122
+
46
123
  # Gets the array of rules.
47
124
  #
48
125
  # @return [Array<PublicSuffix::Rule::*>]
@@ -202,85 +279,5 @@ module PublicSuffix
202
279
  @rules.values_at(*indices).select { |rule| rule.match?(domain) }
203
280
  end
204
281
 
205
-
206
- @@default = nil
207
-
208
- class << self
209
-
210
- # Gets the default rule list.
211
- # Initializes a new {PublicSuffix::List} parsing the content
212
- # of {PublicSuffix::List.default_definition}, if required.
213
- #
214
- # @return [PublicSuffix::List]
215
- def default
216
- @@default ||= parse(default_definition)
217
- end
218
-
219
- # Sets the default rule list to +value+.
220
- #
221
- # @param [PublicSuffix::List] value
222
- # The new rule list.
223
- #
224
- # @return [PublicSuffix::List]
225
- def default=(value)
226
- @@default = value
227
- end
228
-
229
- # Sets the default rule list to +nil+.
230
- #
231
- # @return [self]
232
- def clear
233
- self.default = nil
234
- self
235
- end
236
-
237
- # Resets the default rule list and reinitialize it
238
- # parsing the content of {PublicSuffix::List.default_definition}.
239
- #
240
- # @return [PublicSuffix::List]
241
- def reload
242
- self.clear.default
243
- end
244
-
245
- # Gets the default definition list.
246
- # Can be any <tt>IOStream</tt> including a <tt>File</tt>
247
- # or a simple <tt>String</tt>.
248
- # The object must respond to <tt>#each_line</tt>.
249
- #
250
- # @return [File]
251
- def default_definition
252
- File.new(File.join(File.dirname(__FILE__), "definitions.txt"), "r:utf-8")
253
- end
254
-
255
-
256
- # Parse given +input+ treating the content as Public Suffix List.
257
- #
258
- # See http://publicsuffix.org/format/ for more details about input format.
259
- #
260
- # @param [String] input The rule list to parse.
261
- #
262
- # @return [Array<PublicSuffix::Rule::*>]
263
- def parse(input)
264
- new do |list|
265
- input.each_line do |line|
266
- line.strip!
267
-
268
- # strip blank lines
269
- if line.empty?
270
- next
271
- # strip comments
272
- elsif line =~ %r{^//}
273
- next
274
- # append rule
275
- else
276
- list.add(Rule.factory(line), false)
277
- end
278
- end
279
- end
280
- end
281
-
282
- end
283
-
284
282
  end
285
-
286
283
  end
@@ -12,7 +12,7 @@ module PublicSuffix
12
12
  module Version
13
13
  MAJOR = 1
14
14
  MINOR = 1
15
- PATCH = 1
15
+ PATCH = 2
16
16
  BUILD = nil
17
17
 
18
18
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join(".")
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "public_suffix"
5
- s.version = "1.1.1"
5
+ s.version = "1.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Simone Carletti"]
9
- s.date = "2012-06-26"
9
+ s.date = "2012-09-03"
10
10
  s.description = "PublicSuffix can parse and decompose a domain name into top level domain, domain and subdomains."
11
11
  s.email = "weppos@weppos.net"
12
12
  s.files = [".gemtest", ".gitignore", ".travis.yml", ".yardopts", "CHANGELOG.md", "Gemfile", "LICENSE", "README.md", "Rakefile", "lib/public_suffix.rb", "lib/public_suffix/definitions.txt", "lib/public_suffix/domain.rb", "lib/public_suffix/errors.rb", "lib/public_suffix/list.rb", "lib/public_suffix/rule.rb", "lib/public_suffix/version.rb", "public_suffix.gemspec", "test/acceptance_test.rb", "test/test_helper.rb", "test/unit/domain_test.rb", "test/unit/errors_test.rb", "test/unit/list_test.rb", "test/unit/public_suffix_test.rb", "test/unit/rule_test.rb"]
@@ -97,23 +97,23 @@ class PublicSuffix::ListTest < Test::Unit::TestCase
97
97
 
98
98
 
99
99
  def test_self_default_getter
100
- assert_equal nil, PublicSuffix::List.send(:class_variable_get, :"@@default")
100
+ assert_equal nil, PublicSuffix::List.class_eval { @default }
101
101
  PublicSuffix::List.default
102
- assert_not_equal nil, PublicSuffix::List.send(:class_variable_get, :"@@default")
102
+ assert_not_equal nil, PublicSuffix::List.class_eval { @default }
103
103
  end
104
104
 
105
105
  def test_self_default_setter
106
106
  PublicSuffix::List.default
107
- assert_not_equal nil, PublicSuffix::List.send(:class_variable_get, :"@@default")
107
+ assert_not_equal nil, PublicSuffix::List.class_eval { @default }
108
108
  PublicSuffix::List.default = nil
109
- assert_equal nil, PublicSuffix::List.send(:class_variable_get, :"@@default")
109
+ assert_equal nil, PublicSuffix::List.class_eval { @default }
110
110
  end
111
111
 
112
112
  def test_self_clear
113
113
  PublicSuffix::List.default
114
- assert_not_equal nil, PublicSuffix::List.send(:class_variable_get, :"@@default")
114
+ assert_not_equal nil, PublicSuffix::List.class_eval { @default }
115
115
  PublicSuffix::List.clear
116
- assert_equal nil, PublicSuffix::List.send(:class_variable_get, :"@@default")
116
+ assert_equal nil, PublicSuffix::List.class_eval { @default }
117
117
  end
118
118
 
119
119
  def test_self_reload
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: public_suffix
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-26 00:00:00.000000000 Z
12
+ date: 2012-09-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake