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 CHANGED
@@ -2,4 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  group :test do
4
4
  gem 'rspec'
5
+ gem 'timecop'
5
6
  end
@@ -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', '~> 0.1.4'
74
+ gem 'public-suffix-list'
75
75
 
76
76
  == License
77
77
 
78
- Copyright (c) 2010-2016 Todd Sundsted
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
@@ -6,7 +6,7 @@ require "public_suffix_list/parser.rb"
6
6
 
7
7
  class PublicSuffixList
8
8
 
9
- VERSION = "0.1.5"
9
+ VERSION = "0.1.6"
10
10
 
11
11
  def self.config
12
12
  @@config ||= Config.new
@@ -31,11 +31,7 @@ class PublicSuffixList
31
31
  end
32
32
 
33
33
  def data
34
- @data or (load_data and @data) or @data = {created_at: Time.now, tag: rand(36**8).to_s(36)}
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[key] = value and dump_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?
@@ -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 = public_suffix_list.cache_file.data[: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
- public_suffix_list.cache_file.data[:created_at] = Time.now - 100
25
- public_suffix_list.cache_file.data[:tag] = "1234567890"
26
- public_suffix_list.cache_file.dump_data
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].should_not == created_at
31
- public_suffix_list.cache_file.data[:tag].should_not == 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.5
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: 2016-10-02 00:00:00.000000000 Z
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