public-suffix-list 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ require "public_suffix_list/parser.rb"
6
6
 
7
7
  class PublicSuffixList
8
8
 
9
- VERSION = "0.0.4"
9
+ VERSION = "0.0.5"
10
10
 
11
11
  def self.config
12
12
  @@config ||= Config.new
@@ -38,9 +38,9 @@ class PublicSuffixList
38
38
  if @config.cache_dir
39
39
  @cache_file = CacheFile.new(@config)
40
40
  end
41
- if @config.cache_dir && File.directory?(@config.cache_dir) && File.exist?(File.join(@config.cache_dir, name))
41
+ if @cache_file and @cache_file.exist?
42
42
  uncache or (download and cache)
43
- elsif @config.cache_dir && File.directory?(@config.cache_dir)
43
+ elsif @cache_file
44
44
  download and cache
45
45
  else
46
46
  download
@@ -7,15 +7,11 @@ class PublicSuffixList
7
7
  end
8
8
 
9
9
  def cache?
10
- @config.cache_dir && true
11
- end
12
-
13
- def name
14
- URI.parse(@config.effective_tld_names_url).path.split("/").last + ".cache" if cache?
10
+ @config.cache_dir && File.directory?(@config.cache_dir) && true
15
11
  end
16
12
 
17
13
  def file
18
- File.join(@config.cache_dir, name) if cache?
14
+ File.join(@config.cache_dir, URI.parse(@config.effective_tld_names_url).path.split("/").last + ".cache") if cache?
19
15
  end
20
16
 
21
17
  def exist?
@@ -35,7 +31,7 @@ class PublicSuffixList
35
31
  end
36
32
 
37
33
  def data
38
- @data or (load_data and @data) or @data = {:created_at => Time.now}
34
+ @data or (load_data and @data) or @data = {:created_at => Time.now, :tag => rand(36**8).to_s(36)}
39
35
  end
40
36
 
41
37
  def data=(data)
@@ -46,14 +42,6 @@ class PublicSuffixList
46
42
  !cache? or !([0, nil].include?(@config.cache_expiry_period) or data[:created_at] + @config.cache_expiry_period > Time.now)
47
43
  end
48
44
 
49
- def read_attribute(attribute)
50
- data[attribute]
51
- end
52
-
53
- def write_attribute(attribute, value)
54
- data[attribute] = value
55
- end
56
-
57
45
  end
58
46
 
59
47
  end
data/spec/caching.spec CHANGED
@@ -14,20 +14,21 @@ describe PublicSuffixList do
14
14
  public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
15
15
  public_suffix_list.cache_file.cache?.should be true
16
16
  public_suffix_list.cache_file.exist?.should be true
17
- created_at = public_suffix_list.cache_file.read_attribute(:created_at)
18
- tag = public_suffix_list.cache_file.read_attribute(:tag)
17
+ created_at = public_suffix_list.cache_file.data[:created_at]
18
+ tag = public_suffix_list.cache_file.data[:tag]
19
19
  public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
20
20
  public_suffix_list.cache_file.cache?.should be true
21
21
  public_suffix_list.cache_file.exist?.should be true
22
- public_suffix_list.cache_file.read_attribute(:created_at).should == created_at
23
- public_suffix_list.cache_file.read_attribute(:tag).should == tag
24
- public_suffix_list.cache_file.write_attribute :created_at, Time.now - 100
22
+ public_suffix_list.cache_file.data[:created_at].should == created_at
23
+ public_suffix_list.cache_file.data[:tag].should == tag
24
+ public_suffix_list.cache_file.data[:created_at] = Time.now - 100
25
+ public_suffix_list.cache_file.data[:tag] = "1234567890"
25
26
  public_suffix_list.cache_file.dump_data
26
27
  public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
27
28
  public_suffix_list.cache_file.cache?.should be true
28
29
  public_suffix_list.cache_file.exist?.should be true
29
- public_suffix_list.cache_file.read_attribute(:created_at).should_not == created_at
30
- public_suffix_list.cache_file.read_attribute(:tag).should_not == tag
30
+ public_suffix_list.cache_file.data[:created_at].should_not == created_at
31
+ public_suffix_list.cache_file.data[:tag].should_not == tag
31
32
  end
32
33
 
33
34
  it "should allow 0 or nil to specify an infinite cache expiry period" do
@@ -35,7 +36,7 @@ describe PublicSuffixList do
35
36
  public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
36
37
  public_suffix_list.cache_file.exist?.should be true
37
38
  public_suffix_list.cache_file.expired?.should be false
38
- public_suffix_list.cache_file.write_attribute :created_at, Time.now - 100
39
+ public_suffix_list.cache_file.data[:created_at] = Time.now - 100
39
40
  public_suffix_list.cache_file.expired?.should be true
40
41
  public_suffix_list.cache_file.exist?.should be true
41
42
  public_suffix_list.cache_file.delete
@@ -43,7 +44,7 @@ describe PublicSuffixList do
43
44
  public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 0)
44
45
  public_suffix_list.cache_file.exist?.should be true
45
46
  public_suffix_list.cache_file.expired?.should be false
46
- public_suffix_list.cache_file.write_attribute :created_at, Time.now - 10000000
47
+ public_suffix_list.cache_file.data[:created_at] = Time.now - 10000000
47
48
  public_suffix_list.cache_file.expired?.should be false
48
49
  public_suffix_list.cache_file.exist?.should be true
49
50
  public_suffix_list.cache_file.delete
@@ -51,7 +52,7 @@ describe PublicSuffixList do
51
52
  public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => nil)
52
53
  public_suffix_list.cache_file.exist?.should be true
53
54
  public_suffix_list.cache_file.expired?.should be false
54
- public_suffix_list.cache_file.write_attribute :created_at, Time.now - 10000000
55
+ public_suffix_list.cache_file.data[:created_at] = Time.now - 10000000
55
56
  public_suffix_list.cache_file.expired?.should be false
56
57
  public_suffix_list.cache_file.exist?.should be true
57
58
  end
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.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Sundsted
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-11 00:00:00 -05:00
12
+ date: 2010-01-12 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15