elephas 2.2.0 → 3.0.0

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.
@@ -7,44 +7,41 @@
7
7
  require "spec_helper"
8
8
 
9
9
  describe ::Elephas::Cache do
10
- let(:entry) { ::Elephas::Entry.ensure("VALUE", ::Elephas::Cache.default_prefix + "[KEY]", {ttl: 3600}) }
10
+ let(:entry) { ::Elephas::Entry.ensure("VALUE", ::Elephas::Cache.new(nil).prefix + "[KEY]", {ttl: 3600}) }
11
+ let(:reference) { ::Elephas::Cache.new(::Elephas::Backends::Hash.new) }
11
12
 
12
13
  describe ".use" do
13
- before(:each) do
14
- ::Elephas::Cache.provider = Elephas::Providers::Hash.new
15
- end
16
-
17
14
  it "should use the provider for reading the value" do
18
- ::Elephas::Cache.provider.should_receive(:read)
19
- ::Elephas::Cache.use("KEY") do "VALUE" end
15
+ reference.backend.should_receive(:read)
16
+ reference.use("KEY") do "VALUE" end
20
17
  end
21
18
 
22
19
  it "should skip the provider if requested to" do
23
- ::Elephas::Cache.use("KEY", {ttl: 0}) do "VALUE" end
24
- ::Elephas::Cache.provider.should_not_receive(:read)
25
- ::Elephas::Cache.use("KEY", {force: true}) do "VALUE" end
26
- ::Elephas::Cache.provider.should_not_receive(:read)
20
+ reference.use("KEY", {ttl: 0}) do "VALUE" end
21
+ reference.backend.should_not_receive(:read)
22
+ reference.use("KEY", {force: true}) do "VALUE" end
23
+ reference.backend.should_not_receive(:read)
27
24
  end
28
25
 
29
26
  it "should use the block for value computation" do
30
- expect{ ::Elephas::Cache.use("KEY") do raise ArgumentError end }.to raise_error(ArgumentError)
27
+ expect{ reference.use("KEY") do raise ArgumentError end }.to raise_error(ArgumentError)
31
28
  end
32
29
 
33
30
  it "should not use the block if the value is valid" do
34
- ::Elephas::Cache.use("KEY") do entry end
35
- expect{ ::Elephas::Cache.use("KEY") do raise ArgumentError end }.not_to raise_error(ArgumentError)
31
+ reference.use("KEY") do entry end
32
+ expect{ reference.use("KEY") do raise ArgumentError end }.not_to raise_error(ArgumentError)
36
33
  end
37
34
 
38
35
  it "should store the value in the cache" do
39
- ::Elephas::Cache.use("KEY") do entry end
40
- expect(::Elephas::Cache.provider.read(entry.hash)).to eq(entry)
36
+ reference.use("KEY") do entry end
37
+ expect(reference.backend.read(entry.hash)).to eq(entry)
41
38
  end
42
39
 
43
40
  it "should return the entire entry or only the value" do
44
- ::Elephas::Cache.use("KEY") do "VALUE" end
41
+ reference.use("KEY") do "VALUE" end
45
42
 
46
- expect(::Elephas::Cache.use("KEY")).to eq("VALUE")
47
- value = ::Elephas::Cache.use("KEY", {as_entry: true})
43
+ expect(reference.use("KEY")).to eq("VALUE")
44
+ value = reference.use("KEY", {as_entry: true})
48
45
  expect(value).to be_a(::Elephas::Entry)
49
46
  expect(value.value).to eq("VALUE")
50
47
  end
@@ -52,36 +49,36 @@ describe ::Elephas::Cache do
52
49
 
53
50
  describe ".read" do
54
51
  it "should be forwarded to the provider" do
55
- ::Elephas::Cache.provider.should_receive(:read)
56
- ::Elephas::Cache.read("KEY")
52
+ reference.backend.should_receive(:read)
53
+ reference.read("KEY")
57
54
  end
58
55
  end
59
56
 
60
57
  describe ".write" do
61
58
  it "should be forwarded to the provider" do
62
- ::Elephas::Cache.provider.should_receive(:write)
63
- ::Elephas::Cache.write("KEY", "VALUE")
59
+ reference.backend.should_receive(:write)
60
+ reference.write("KEY", "VALUE")
64
61
  end
65
62
  end
66
63
 
67
64
  describe ".delete" do
68
65
  it "should be forwarded to the provider" do
69
- ::Elephas::Cache.provider.should_receive(:delete)
70
- ::Elephas::Cache.delete("KEY")
66
+ reference.backend.should_receive(:delete)
67
+ reference.delete("KEY")
71
68
  end
72
69
  end
73
70
 
74
71
  describe ".exists?" do
75
72
  it "should be forwarded to the provider" do
76
- ::Elephas::Cache.provider.should_receive(:exists?)
77
- ::Elephas::Cache.exists?("KEY")
73
+ reference.backend.should_receive(:exists?)
74
+ reference.exists?("KEY")
78
75
  end
79
76
  end
80
77
 
81
78
  describe "setup_options" do
82
79
  it "should set good defaults for options" do
83
80
  hashes = {
84
- base: ::Elephas::Entry.hashify_key("#{::Elephas::Cache.default_prefix}[KEY]"),
81
+ base: ::Elephas::Entry.hashify_key("#{reference.prefix}[KEY]"),
85
82
  alternative: ::Elephas::Entry.hashify_key("prefix[KEY]")
86
83
  }
87
84
 
@@ -96,17 +93,17 @@ describe ::Elephas::Cache do
96
93
  ]
97
94
 
98
95
  reference_hashes = [
99
- {key: "KEY", ttl: 1.hour * 1000, force: false, as_entry: false, prefix: ::Elephas::Cache.default_prefix, complete_key: "#{::Elephas::Cache.default_prefix}[KEY]", hash: hashes[:base]},
100
- {key: "KEY", ttl: 1.hour * 1000, force: false, as_entry: false, prefix: ::Elephas::Cache.default_prefix, complete_key: "#{::Elephas::Cache.default_prefix}[KEY]", hash: hashes[:base]},
101
- {key: "KEY", ttl: 2.hour, force: false, as_entry: false, prefix: ::Elephas::Cache.default_prefix, complete_key: "#{::Elephas::Cache.default_prefix}[KEY]", hash: hashes[:base]},
102
- {key: "KEY", ttl: 1.hour * 1000, force: true, as_entry: false, prefix: ::Elephas::Cache.default_prefix, complete_key: "#{::Elephas::Cache.default_prefix}[KEY]", hash: hashes[:base]},
103
- {key: "KEY", ttl: 1.hour * 1000, force: false, as_entry: true, prefix: ::Elephas::Cache.default_prefix, complete_key: "#{::Elephas::Cache.default_prefix}[KEY]", hash: hashes[:base]},
96
+ {key: "KEY", ttl: 1.hour * 1000, force: false, as_entry: false, prefix: reference.prefix, complete_key: "#{reference.prefix}[KEY]", hash: hashes[:base]},
97
+ {key: "KEY", ttl: 1.hour * 1000, force: false, as_entry: false, prefix: reference.prefix, complete_key: "#{reference.prefix}[KEY]", hash: hashes[:base]},
98
+ {key: "KEY", ttl: 2.hour, force: false, as_entry: false, prefix: reference.prefix, complete_key: "#{reference.prefix}[KEY]", hash: hashes[:base]},
99
+ {key: "KEY", ttl: 1.hour * 1000, force: true, as_entry: false, prefix: reference.prefix, complete_key: "#{reference.prefix}[KEY]", hash: hashes[:base]},
100
+ {key: "KEY", ttl: 1.hour * 1000, force: false, as_entry: true, prefix: reference.prefix, complete_key: "#{reference.prefix}[KEY]", hash: hashes[:base]},
104
101
  {key: "KEY", ttl: 1.hour * 1000, force: false, as_entry: false, prefix: "prefix", complete_key: "prefix[KEY]", hash: hashes[:alternative]},
105
- {key: "KEY", ttl: 1.hour * 1000, force: false, as_entry: false, prefix: ::Elephas::Cache.default_prefix, complete_key: "#{::Elephas::Cache.default_prefix}[KEY]", hash: "hash"}
102
+ {key: "KEY", ttl: 1.hour * 1000, force: false, as_entry: false, prefix: reference.prefix, complete_key: "#{reference.prefix}[KEY]", hash: "hash"}
106
103
  ]
107
104
 
108
105
  options_hashes.each_with_index do |options, i|
109
- expect(::Elephas::Cache.setup_options(options, "KEY")).to eq(reference_hashes[i])
106
+ expect(reference.setup_options(options, "KEY")).to eq(reference_hashes[i])
110
107
  end
111
108
  end
112
109
  end
@@ -7,6 +7,7 @@
7
7
  require "spec_helper"
8
8
 
9
9
  describe Elephas::Entry do
10
+ let(:backend) { ::Elephas::Backends::Hash.new }
10
11
  subject { ::Elephas::Entry.new("KEY", "VALUE") }
11
12
 
12
13
  describe "#initialize" do
@@ -41,9 +42,9 @@ describe Elephas::Entry do
41
42
  end
42
43
 
43
44
  it "should save to the cache" do
44
- expect(::Elephas::Cache.provider.read(subject.hash)).not_to eq(subject)
45
- subject.refresh(true)
46
- expect(::Elephas::Cache.provider.read(subject.hash)).to eq(subject)
45
+ expect(backend.read(subject.hash)).not_to eq(subject)
46
+ subject.refresh(true, backend)
47
+ expect(backend.read(subject.hash)).to eq(subject)
47
48
  end
48
49
  end
49
50
 
@@ -54,13 +55,13 @@ describe Elephas::Entry do
54
55
 
55
56
  it "should return true if the ttl is still valid" do
56
57
  ::Time.stub(:now).and_return(1000)
57
- expect(subject.valid?).to be_true
58
+ expect(subject.valid?(backend)).to be_true
58
59
  end
59
60
 
60
61
  it "should return true if the ttl has expired" do
61
62
  ::Time.stub(:now).and_return(10000)
62
63
  subject.updated_at = 1000
63
- expect(subject.valid?).to be_false
64
+ expect(subject.valid?(backend)).to be_false
64
65
  end
65
66
  end
66
67
 
@@ -6,12 +6,8 @@
6
6
 
7
7
  require "spec_helper"
8
8
 
9
- describe Elephas::Providers::Base do
10
- class BaseProvider
11
- include Elephas::Providers::Base
12
- end
13
-
14
- let(:provider) { BaseProvider.new }
9
+ describe Elephas::Backends::Base do
10
+ let(:provider) { Elephas::Backends::Base.new }
15
11
 
16
12
  describe ".read" do
17
13
  it "should raise an ArgumentError exception" do
@@ -6,22 +6,22 @@
6
6
 
7
7
  require "spec_helper"
8
8
 
9
- describe Elephas::Providers::Hash do
10
- subject { ::Elephas::Providers::Hash.new }
9
+ describe Elephas::Backends::Hash do
10
+ subject { ::Elephas::Backends::Hash.new }
11
11
  let!(:value) { subject.write("KEY", ::Elephas::Entry.ensure("VALUE", "KEY", {ttl: 3600})) }
12
12
 
13
13
  describe "#initialize" do
14
14
  it "should create a store with an empty hash" do
15
- expect(::Elephas::Providers::Hash.new.data).to eq({})
15
+ expect(::Elephas::Backends::Hash.new.data).to eq({})
16
16
  end
17
17
 
18
18
  it "should create a store with an given hash" do
19
- expect(::Elephas::Providers::Hash.new({a: :b}).data).to eq({a: :b})
19
+ expect(::Elephas::Backends::Hash.new({a: :b}).data).to eq({a: :b})
20
20
  end
21
21
 
22
22
  it "should ensure that the store is an Hash" do
23
- expect(::Elephas::Providers::Hash.new(nil).data).to eq({})
24
- expect(::Elephas::Providers::Hash.new("INVALID").data).to eq({})
23
+ expect(::Elephas::Backends::Hash.new(nil).data).to eq({})
24
+ expect(::Elephas::Backends::Hash.new("INVALID").data).to eq({})
25
25
  end
26
26
  end
27
27
 
@@ -6,7 +6,7 @@
6
6
 
7
7
  require "spec_helper"
8
8
 
9
- describe Elephas::Providers::RubyOnRails do
9
+ describe Elephas::Backends::RubyOnRails do
10
10
  class TempRailsCache < Hash # This class simulate the presence of Rails
11
11
  def read(key)
12
12
  self[key]
@@ -28,7 +28,7 @@ describe Elephas::Providers::RubyOnRails do
28
28
  end
29
29
  end
30
30
 
31
- subject { ::Elephas::Providers::RubyOnRails.new }
31
+ subject { ::Elephas::Backends::RubyOnRails.new }
32
32
  let!(:value) { subject.write("KEY", ::Elephas::Entry.ensure("VALUE", "KEY", {ttl: 3600})) }
33
33
 
34
34
  describe "#read" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elephas
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 3.0.0
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: 2013-02-28 00:00:00.000000000 Z
12
+ date: 2013-03-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: lazier
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 2.7.0
21
+ version: 2.8.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 2.7.0
29
+ version: 2.8.0
30
30
  description: A storage agnostic caching framework.
31
31
  email:
32
32
  - shogun_panda@me.com
@@ -42,12 +42,12 @@ files:
42
42
  - README.md
43
43
  - Rakefile
44
44
  - doc/Elephas.html
45
+ - doc/Elephas/Backends.html
46
+ - doc/Elephas/Backends/Base.html
47
+ - doc/Elephas/Backends/Hash.html
48
+ - doc/Elephas/Backends/RubyOnRails.html
45
49
  - doc/Elephas/Cache.html
46
50
  - doc/Elephas/Entry.html
47
- - doc/Elephas/Providers.html
48
- - doc/Elephas/Providers/Base.html
49
- - doc/Elephas/Providers/Hash.html
50
- - doc/Elephas/Providers/RubyOnRails.html
51
51
  - doc/Elephas/Version.html
52
52
  - doc/_index.html
53
53
  - doc/class_list.html
@@ -65,18 +65,18 @@ files:
65
65
  - doc/top-level-namespace.html
66
66
  - elephas.gemspec
67
67
  - lib/elephas.rb
68
+ - lib/elephas/backends/base.rb
69
+ - lib/elephas/backends/hash.rb
70
+ - lib/elephas/backends/ruby_on_rails.rb
68
71
  - lib/elephas/cache.rb
69
72
  - lib/elephas/entry.rb
70
- - lib/elephas/provider.rb
71
- - lib/elephas/providers/hash.rb
72
- - lib/elephas/providers/ruby_on_rails.rb
73
73
  - lib/elephas/version.rb
74
74
  - locales/en.yml
75
75
  - locales/it.yml
76
76
  - spec/coverage_helper.rb
77
77
  - spec/elephas/cache_spec.rb
78
78
  - spec/elephas/entry_spec.rb
79
- - spec/elephas/provider_spec.rb
79
+ - spec/elephas/providers/base_spec.rb
80
80
  - spec/elephas/providers/hash_spec.rb
81
81
  - spec/elephas/providers/ruby_on_rails_spec.rb
82
82
  - spec/spec_helper.rb
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  segments:
102
102
  - 0
103
- hash: 3747223842463802864
103
+ hash: 3158836318687303019
104
104
  requirements: []
105
105
  rubyforge_project: elephas
106
106
  rubygems_version: 1.8.25
@@ -111,7 +111,7 @@ test_files:
111
111
  - spec/coverage_helper.rb
112
112
  - spec/elephas/cache_spec.rb
113
113
  - spec/elephas/entry_spec.rb
114
- - spec/elephas/provider_spec.rb
114
+ - spec/elephas/providers/base_spec.rb
115
115
  - spec/elephas/providers/hash_spec.rb
116
116
  - spec/elephas/providers/ruby_on_rails_spec.rb
117
117
  - spec/spec_helper.rb