public-suffix-list 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/README.rdoc +2 -2
- data/lib/public_suffix_list.rb +1 -1
- data/lib/public_suffix_list/cache_file.rb +2 -6
- data/spec/caching.spec +31 -6
- metadata +2 -2
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -71,11 +71,11 @@ Install the gem directly:
|
|
71
71
|
|
72
72
|
Or add it to your Gemfile and use bundler:
|
73
73
|
|
74
|
-
gem 'public-suffix-list'
|
74
|
+
gem 'public-suffix-list'
|
75
75
|
|
76
76
|
== License
|
77
77
|
|
78
|
-
Copyright (c) 2010-
|
78
|
+
Copyright (c) 2010-2017 Todd Sundsted
|
79
79
|
|
80
80
|
Permission is hereby granted, free of charge, to any person obtaining
|
81
81
|
a copy of this software and associated documentation files (the
|
data/lib/public_suffix_list.rb
CHANGED
@@ -31,11 +31,7 @@ class PublicSuffixList
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def data
|
34
|
-
@data or (load_data and @data) or @data = {
|
35
|
-
end
|
36
|
-
|
37
|
-
def data=(data)
|
38
|
-
@data = data and dump_data
|
34
|
+
@data or (load_data and @data) or @data = {}
|
39
35
|
end
|
40
36
|
|
41
37
|
def [](key)
|
@@ -43,7 +39,7 @@ class PublicSuffixList
|
|
43
39
|
end
|
44
40
|
|
45
41
|
def []=(key, value)
|
46
|
-
data
|
42
|
+
data.merge!({key => value, created_at: Time.now, tag: rand(36**8).to_s(36)}) and dump_data
|
47
43
|
end
|
48
44
|
|
49
45
|
def expired?
|
data/spec/caching.spec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'tmpdir'
|
2
2
|
require 'public_suffix_list'
|
3
|
+
require 'timecop'
|
3
4
|
|
4
5
|
describe PublicSuffixList do
|
5
6
|
|
@@ -15,20 +16,44 @@ describe PublicSuffixList do
|
|
15
16
|
public_suffix_list.cache_file.cache?.should be true
|
16
17
|
public_suffix_list.cache_file.exist?.should be true
|
17
18
|
created_at = public_suffix_list.cache_file.data[:created_at]
|
18
|
-
tag
|
19
|
+
tag = public_suffix_list.cache_file.data[:tag]
|
19
20
|
public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
|
20
21
|
public_suffix_list.cache_file.cache?.should be true
|
21
22
|
public_suffix_list.cache_file.exist?.should be true
|
22
23
|
public_suffix_list.cache_file.data[:created_at].should == created_at
|
23
24
|
public_suffix_list.cache_file.data[:tag].should == tag
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should fetch a new data file when the cache expiry has passed" do
|
28
|
+
File.exist?(FILE).should be false
|
29
|
+
public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
|
30
|
+
public_suffix_list.cache_file.cache?.should be true
|
31
|
+
public_suffix_list.cache_file.exist?.should be true
|
32
|
+
created_at = public_suffix_list.cache_file.data[:created_at]
|
33
|
+
tag = public_suffix_list.cache_file.data[:tag]
|
34
|
+
Timecop.travel(Time.now + 15) do
|
35
|
+
public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
|
36
|
+
public_suffix_list.cache_file.cache?.should be true
|
37
|
+
public_suffix_list.cache_file.exist?.should be true
|
38
|
+
public_suffix_list.cache_file.data[:created_at].should_not == created_at
|
39
|
+
public_suffix_list.cache_file.data[:tag].should_not == tag
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should not fetch a new data file when the cache expiry has not passed" do
|
44
|
+
File.exist?(FILE).should be false
|
27
45
|
public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
|
28
46
|
public_suffix_list.cache_file.cache?.should be true
|
29
47
|
public_suffix_list.cache_file.exist?.should be true
|
30
|
-
public_suffix_list.cache_file.data[:created_at]
|
31
|
-
public_suffix_list.cache_file.data[:tag]
|
48
|
+
created_at = public_suffix_list.cache_file.data[:created_at]
|
49
|
+
tag = public_suffix_list.cache_file.data[:tag]
|
50
|
+
Timecop.travel(Time.now + 5) do
|
51
|
+
public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
|
52
|
+
public_suffix_list.cache_file.cache?.should be true
|
53
|
+
public_suffix_list.cache_file.exist?.should be true
|
54
|
+
public_suffix_list.cache_file.data[:created_at].should == created_at
|
55
|
+
public_suffix_list.cache_file.data[:tag].should == tag
|
56
|
+
end
|
32
57
|
end
|
33
58
|
|
34
59
|
it "should allow 0 or nil to specify an infinite cache expiry period" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: public-suffix-list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
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:
|
12
|
+
date: 2017-06-15 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: The Public Suffix List (http://publicsuffix.org/) is "a cross-vendor
|
15
15
|
initiative to provide an accurate list of domain name suffixes". Such a list is
|