ryodo 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rbenv-gemsets +1 -0
- data/.rbenv-version +1 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +16 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +46 -0
- data/LICENSE.txt +20 -0
- data/README.md +72 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/checks/matching.rb +89 -0
- data/data/suffix.dat +4317 -0
- data/lib/ryodo/convenience/.u.rb +19 -0
- data/lib/ryodo/convenience.rb +13 -0
- data/lib/ryodo/domain.rb +83 -0
- data/lib/ryodo/ext/string.rb +9 -0
- data/lib/ryodo/methods.rb +12 -0
- data/lib/ryodo/parser.rb +37 -0
- data/lib/ryodo/rule.rb +15 -0
- data/lib/ryodo/rule_set.rb +77 -0
- data/lib/ryodo/suffix_list.rb +57 -0
- data/lib/ryodo/suffix_list_fetcher.rb +54 -0
- data/lib/ryodo.rb +29 -0
- data/spec/_files/mozilla_effective_tld_names.dat +5229 -0
- data/spec/ryodo/suffix_list_fetcher_spec.rb +81 -0
- data/spec/ryodo/suffix_list_spec.rb +50 -0
- data/spec/ryodo_spec.rb +6 -0
- data/spec/spec_helper.rb +37 -0
- metadata +192 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "ryodo/suffix_list_fetcher"
|
3
|
+
require File.expand_path("../../spec_helper.rb", __FILE__)
|
4
|
+
|
5
|
+
describe Ryodo::SuffixListFetcher do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@custom_uri = "http://custom.suffix.list.example.com/foo-bar.dat"
|
9
|
+
@custom_storage = "#{RYODO_TMP_ROOT}/custom-storage-path.dat"
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
Dir["#{RYODO_TMP_ROOT}/**/*"].each do |file|
|
14
|
+
File.delete(file)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "#new creates a new instance with predefined vars" do
|
19
|
+
fetcher = described_class.new
|
20
|
+
|
21
|
+
fetcher.instance_variable_get("@uri").should == URI(Ryodo::PUBLIC_SUFFIX_DATA_URI)
|
22
|
+
fetcher.instance_variable_get("@store").should == Ryodo::PUBLIC_SUFFIX_STORE
|
23
|
+
end
|
24
|
+
|
25
|
+
it "#new creates a new instance with custom vars" do
|
26
|
+
|
27
|
+
fetcher = described_class.new(@custom_uri, @custom_storage)
|
28
|
+
|
29
|
+
fetcher.instance_variable_get("@uri").should == URI(@custom_uri)
|
30
|
+
fetcher.instance_variable_get("@store").should == @custom_storage
|
31
|
+
end
|
32
|
+
|
33
|
+
context "data retrieval and storage" do
|
34
|
+
|
35
|
+
let(:fetcher){ described_class.new }
|
36
|
+
|
37
|
+
it "#fetch_data retrieves remote data" do
|
38
|
+
fetcher.fetch_data
|
39
|
+
|
40
|
+
fetcher.instance_variable_get("@fetched_data").should be_kind_of(Enumerator)
|
41
|
+
fetcher.instance_variable_get("@fetched_data").first.should =~ /BEGIN LICENSE BLOCK/
|
42
|
+
end
|
43
|
+
|
44
|
+
it "#save_data stores fetched data into file (as cleaned set)" do
|
45
|
+
fetcher.fetch_data
|
46
|
+
fetcher.instance_variable_set("@prepared_data", ["dummy data"])
|
47
|
+
|
48
|
+
File.should_receive(:open).with(Ryodo::PUBLIC_SUFFIX_STORE,"w")
|
49
|
+
fetcher.save_data
|
50
|
+
end
|
51
|
+
|
52
|
+
it "#prepare_data manipulates and cleans data for storage" do
|
53
|
+
fetcher.fetch_data
|
54
|
+
prepared_data = fetcher.prepare_data
|
55
|
+
|
56
|
+
prepared_data.should be_an(Array)
|
57
|
+
prepared_data.none?{|e| e =~ /^\/\//}.should be_true # no comment lines
|
58
|
+
prepared_data.none?{|e| e =~ /^\n/}.should be_true # no empty lines
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
context ".fetch_and_save! does all jobs" do
|
64
|
+
|
65
|
+
before do
|
66
|
+
@valid_uri = Ryodo::PUBLIC_SUFFIX_DATA_URI
|
67
|
+
@invalid_uri = "#{Ryodo::PUBLIC_SUFFIX_DATA_URI}&invalid_file"
|
68
|
+
@storage = "#{RYODO_TMP_ROOT}/suffixes.dat"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "and returns true if successful" do
|
72
|
+
described_class.fetch_and_save!(@valid_uri, @storage).should be_true
|
73
|
+
end
|
74
|
+
|
75
|
+
it "and returns false if something failed" do
|
76
|
+
described_class.fetch_and_save!(@invalid_uri, @storage).should be_false
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path("../../spec_helper.rb", __FILE__)
|
3
|
+
|
4
|
+
describe Ryodo::SuffixList do
|
5
|
+
|
6
|
+
context "singleton" do
|
7
|
+
|
8
|
+
it "cannot be instanciated via #new" do
|
9
|
+
expect{ described_class.new }.to raise_error
|
10
|
+
end
|
11
|
+
|
12
|
+
it "creates instance by calling the class itself" do
|
13
|
+
described_class.should_receive(:instance)
|
14
|
+
described_class.send(:"SuffixList")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "instance check" do
|
18
|
+
o1 = described_class
|
19
|
+
o2 = described_class
|
20
|
+
|
21
|
+
o1.should == o2
|
22
|
+
end
|
23
|
+
|
24
|
+
it "has .instance" do
|
25
|
+
described_class.methods.should include(:"instance")
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
context "methods" do
|
31
|
+
|
32
|
+
let(:described_instance){ described_class.instance }
|
33
|
+
|
34
|
+
it ".reload can retrieve a fresh suffix list" do
|
35
|
+
described_instance.should_receive(:load_file).and_return(true)
|
36
|
+
described_class.reload
|
37
|
+
end
|
38
|
+
|
39
|
+
it ".reload fails if given file doesn't exist" do
|
40
|
+
expect { described_class.reload("#{RYODO_TMP_ROOT}/invalid-file.dat") }.to raise_error
|
41
|
+
end
|
42
|
+
|
43
|
+
it ".list returns an array of arrays" do
|
44
|
+
described_class.list.should be_kind_of(Array)
|
45
|
+
described_class.list.any?{|e|e.is_a?(Array)}.should be_true
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/spec/ryodo_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$:.push(File.expand_path("../../lib", __FILE__))
|
4
|
+
|
5
|
+
require "fakeweb"
|
6
|
+
require "uri"
|
7
|
+
require "ryodo"
|
8
|
+
|
9
|
+
RSpec::Matchers.define :include_hash do |expected|
|
10
|
+
|
11
|
+
match do |actual|
|
12
|
+
actual.is_a?(Hash) &&
|
13
|
+
expected.is_a?(Hash) &&
|
14
|
+
(actual.keys & expected.keys) == expected.keys &&
|
15
|
+
!(expected.keys.inject([]){|m,k|
|
16
|
+
m << expected.has_value?(actual[k])
|
17
|
+
}.uniq.include?(false))
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
RYODO_SPEC_ROOT = File.expand_path("..", __FILE__)
|
23
|
+
RYODO_TMP_ROOT = File.expand_path("../../tmp", __FILE__)
|
24
|
+
|
25
|
+
Dir.mkdir RYODO_TMP_ROOT unless File.exists?(RYODO_TMP_ROOT)
|
26
|
+
|
27
|
+
FakeWeb.register_uri(:get,
|
28
|
+
Ryodo::PUBLIC_SUFFIX_DATA_URI,
|
29
|
+
:body => File.read("#{RYODO_SPEC_ROOT}/_files/mozilla_effective_tld_names.dat")
|
30
|
+
)
|
31
|
+
|
32
|
+
FakeWeb.register_uri(
|
33
|
+
:get,
|
34
|
+
"#{Ryodo::PUBLIC_SUFFIX_DATA_URI}&invalid_file",
|
35
|
+
:body => "Oops!",
|
36
|
+
:status => [404,"Not Found"]
|
37
|
+
)
|
metadata
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ryodo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christoph Grabo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: jeweler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: fakeweb
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: pry
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: pry-doc
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: ryōdo【領土】 りょうど — A domain name parser gem
|
127
|
+
email: chris@dinarrr.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files:
|
131
|
+
- LICENSE.txt
|
132
|
+
- README.md
|
133
|
+
files:
|
134
|
+
- .document
|
135
|
+
- .rbenv-gemsets
|
136
|
+
- .rbenv-version
|
137
|
+
- .rspec
|
138
|
+
- .ruby-version
|
139
|
+
- .travis.yml
|
140
|
+
- Gemfile
|
141
|
+
- Gemfile.lock
|
142
|
+
- LICENSE.txt
|
143
|
+
- README.md
|
144
|
+
- Rakefile
|
145
|
+
- VERSION
|
146
|
+
- checks/matching.rb
|
147
|
+
- data/suffix.dat
|
148
|
+
- lib/ryodo.rb
|
149
|
+
- lib/ryodo/convenience.rb
|
150
|
+
- lib/ryodo/convenience/.u.rb
|
151
|
+
- lib/ryodo/domain.rb
|
152
|
+
- lib/ryodo/ext/string.rb
|
153
|
+
- lib/ryodo/methods.rb
|
154
|
+
- lib/ryodo/parser.rb
|
155
|
+
- lib/ryodo/rule.rb
|
156
|
+
- lib/ryodo/rule_set.rb
|
157
|
+
- lib/ryodo/suffix_list.rb
|
158
|
+
- lib/ryodo/suffix_list_fetcher.rb
|
159
|
+
- spec/_files/mozilla_effective_tld_names.dat
|
160
|
+
- spec/ryodo/suffix_list_fetcher_spec.rb
|
161
|
+
- spec/ryodo/suffix_list_spec.rb
|
162
|
+
- spec/ryodo_spec.rb
|
163
|
+
- spec/spec_helper.rb
|
164
|
+
homepage: http://github.com/asaaki/ryodo
|
165
|
+
licenses:
|
166
|
+
- MIT
|
167
|
+
post_install_message:
|
168
|
+
rdoc_options: []
|
169
|
+
require_paths:
|
170
|
+
- lib
|
171
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
172
|
+
none: false
|
173
|
+
requirements:
|
174
|
+
- - ! '>='
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
segments:
|
178
|
+
- 0
|
179
|
+
hash: -4464656290127466025
|
180
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
|
+
none: false
|
182
|
+
requirements:
|
183
|
+
- - ! '>='
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0'
|
186
|
+
requirements: []
|
187
|
+
rubyforge_project:
|
188
|
+
rubygems_version: 1.8.23
|
189
|
+
signing_key:
|
190
|
+
specification_version: 3
|
191
|
+
summary: ryōdo【領土】 りょうど — A domain name parser
|
192
|
+
test_files: []
|