elephas 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.gitignore +5 -0
  2. data/.travis.yml +8 -0
  3. data/.yardopts +1 -0
  4. data/Gemfile +9 -0
  5. data/README.md +28 -0
  6. data/Rakefile +18 -0
  7. data/doc/Elephas/Cache.html +815 -0
  8. data/doc/Elephas/Entry.html +1085 -0
  9. data/doc/Elephas/Exceptions.html +115 -0
  10. data/doc/Elephas/Providers/Base.html +701 -0
  11. data/doc/Elephas/Providers/Hash.html +775 -0
  12. data/doc/Elephas/Providers/RubyOnRails.html +609 -0
  13. data/doc/Elephas/Providers.html +129 -0
  14. data/doc/Elephas/Version.html +189 -0
  15. data/doc/Elephas.html +130 -0
  16. data/doc/_index.html +207 -0
  17. data/doc/class_list.html +53 -0
  18. data/doc/css/common.css +1 -0
  19. data/doc/css/full_list.css +57 -0
  20. data/doc/css/style.css +328 -0
  21. data/doc/file.README.html +103 -0
  22. data/doc/file_list.html +55 -0
  23. data/doc/frames.html +28 -0
  24. data/doc/index.html +103 -0
  25. data/doc/js/app.js +214 -0
  26. data/doc/js/full_list.js +173 -0
  27. data/doc/js/jquery.js +4 -0
  28. data/doc/method_list.html +300 -0
  29. data/doc/top-level-namespace.html +112 -0
  30. data/elephas.gemspec +34 -0
  31. data/lib/elephas/cache.rb +89 -0
  32. data/lib/elephas/entry.rb +86 -0
  33. data/lib/elephas/provider.rb +57 -0
  34. data/lib/elephas/providers/hash.rb +65 -0
  35. data/lib/elephas/providers/ruby_on_rails.rb +57 -0
  36. data/lib/elephas/version.rb +25 -0
  37. data/lib/elephas.rb +20 -0
  38. data/spec/coverage_helper.rb +19 -0
  39. data/spec/elephas/cache_spec.rb +41 -0
  40. data/spec/elephas/entry_spec.rb +11 -0
  41. data/spec/elephas/provider_spec.rb +46 -0
  42. data/spec/elephas/providers/hash_spec.rb +80 -0
  43. data/spec/elephas/providers/ruby_on_rails_spec.rb +86 -0
  44. data/spec/spec_helper.rb +16 -0
  45. metadata +231 -0
@@ -0,0 +1,80 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the elephas gem. Copyright (C) 2012 and above Shogun <shogun_panda@me.com>.
4
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
+ #
6
+
7
+ require "spec_helper"
8
+
9
+ describe Elephas::Providers::Hash do
10
+ subject { ::Elephas::Providers::Hash.new }
11
+ let!(:value) { subject.write("KEY", ::Elephas::Entry.ensure("VALUE", "KEY", {:ttl => 3600})) }
12
+
13
+ describe "#initialize" do
14
+ it "should create a store with an empty hash" do
15
+ expect(::Elephas::Providers::Hash.new.data).to eq({})
16
+ end
17
+
18
+ it "should create a store with an given hash" do
19
+ expect(::Elephas::Providers::Hash.new({:a => :b}).data).to eq({:a => :b})
20
+ end
21
+
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({})
25
+ end
26
+ end
27
+
28
+ describe "#read" do
29
+ it "fetch data from the hash" do
30
+ expect(subject.read("KEY")).to be_a(::Elephas::Entry)
31
+ expect(subject.read("KEY").value).to eq("VALUE")
32
+ end
33
+
34
+ it "return nil for missing or expired values" do
35
+ subject.data["KEY"].updated_at = Time.now.to_f - 3700
36
+
37
+ expect(subject.read("KEY")).to be_nil
38
+ expect(subject.read("INVALID")).to be_nil
39
+ end
40
+ end
41
+
42
+ describe "#write" do
43
+ it "should save data to the hash" do
44
+ expect(subject.data["KEY"]).to be_a(::Elephas::Entry)
45
+ expect(subject.data["KEY"].key).to eq("KEY")
46
+ expect(subject.data["KEY"].value).to eq("VALUE")
47
+ end
48
+
49
+ it "should save data and update TTL" do
50
+ updated_at = value.updated_at
51
+
52
+ expect(subject.write("KEY", value)).to eq(value)
53
+ expect(value.updated_at).not_to eq(updated_at)
54
+ end
55
+ end
56
+
57
+ describe "#delete" do
58
+ it "should delete a stored value and return true" do
59
+ expect(subject.delete("KEY")).to be_true
60
+ expect(subject.data["KEY"]).to be_nil
61
+ end
62
+
63
+ it "should return false if the value doesn't exists" do
64
+ expect(subject.delete("INVALID")).to be_false
65
+ end
66
+ end
67
+
68
+ describe "#exists?" do
69
+ it "returns true for valid keys" do
70
+ expect(subject.exists?("KEY")).to be_true
71
+ end
72
+
73
+ it "returns false for invalid or expired keys" do
74
+ subject.data["KEY"].updated_at = Time.now.to_f - 3700
75
+
76
+ expect(subject.exists?("KEY")).to be_false
77
+ expect(subject.exists?("INVALID")).to be_false
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,86 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the elephas gem. Copyright (C) 2012 and above Shogun <shogun_panda@me.com>.
4
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
+ #
6
+
7
+ require "spec_helper"
8
+
9
+ describe Elephas::Providers::RubyOnRails do
10
+ class TempRailsCache < Hash # This class simulate the presence of Rails
11
+ def read(key)
12
+ self[key]
13
+ end
14
+
15
+ def write(key, value, options = {})
16
+ self[key] = value
17
+ end
18
+
19
+ def exist?(key)
20
+ self.has_key?(key)
21
+ end
22
+ end
23
+
24
+ class Rails
25
+ def self.cache
26
+ @cache ||= TempRailsCache.new
27
+ end
28
+ end
29
+
30
+ subject { ::Elephas::Providers::RubyOnRails.new }
31
+ let!(:value) { subject.write("KEY", ::Elephas::Entry.ensure("VALUE", "KEY", {:ttl => 3600})) }
32
+
33
+ describe "#read" do
34
+ it "fetch data from the cache" do
35
+ expect(subject.read("KEY")).to be_a(::Elephas::Entry)
36
+ expect(subject.read("KEY").value).to eq("VALUE")
37
+ end
38
+
39
+ it "return nil for missing or expired values" do
40
+ Rails.cache.read("KEY").updated_at = Time.now.to_f - 3700
41
+
42
+ expect(subject.read("KEY")).to be_nil
43
+ expect(subject.read("INVALID")).to be_nil
44
+ end
45
+ end
46
+
47
+ describe "#write" do
48
+ it "should save data to the hash" do
49
+ expect(Rails.cache.read("KEY")).to be_a(::Elephas::Entry)
50
+ expect(Rails.cache.read("KEY").key).to eq("KEY")
51
+ expect(Rails.cache.read("KEY").value).to eq("VALUE")
52
+ end
53
+
54
+ it "should save data and update TTL" do
55
+ value = Rails.cache.read("KEY")
56
+ updated_at = value.updated_at
57
+
58
+ expect(subject.write("KEY", value)).to eq(value)
59
+ expect(value.updated_at).not_to eq(updated_at)
60
+ end
61
+ end
62
+
63
+ describe "#delete" do
64
+ it "should delete a stored value and return true" do
65
+ expect(subject.delete("KEY")).to be_true
66
+ expect(Rails.cache.read("KEY")).to be_nil
67
+ end
68
+
69
+ it "should return false if the value doesn't exists" do
70
+ expect(subject.delete("INVALID")).to be_false
71
+ end
72
+ end
73
+
74
+ describe "#exists?" do
75
+ it "returns true for valid keys" do
76
+ expect(subject.exists?("KEY")).to be_true
77
+ end
78
+
79
+ it "returns false for invalid or expired keys" do
80
+ Rails.cache.read("KEY").updated_at = Time.now.to_f - 3700
81
+
82
+ expect(subject.exists?("KEY")).to be_false
83
+ expect(subject.exists?("INVALID")).to be_false
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the elephas gem. Copyright (C) 2012 and above Shogun <shogun_panda@me.com>.
4
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
+ #
6
+
7
+ require "rubygems"
8
+ require "coverage_helper"
9
+ require "bundler/setup"
10
+ require "elephas"
11
+
12
+ RSpec.configure do |config|
13
+ config.expect_with :rspec do |c|
14
+ c.syntax = :expect
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,231 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elephas
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Shogun
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cowtech-extensions
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.7.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.7.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.11.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: 2.11.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.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.9.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.6.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.6.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.9.10
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.9.10
94
+ - !ruby/object:Gem::Dependency
95
+ name: yard
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 0.8.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.8.0
110
+ - !ruby/object:Gem::Dependency
111
+ name: redcarpet
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 2.1.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: 2.1.0
126
+ - !ruby/object:Gem::Dependency
127
+ name: github-markup
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 0.7.0
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 0.7.0
142
+ description: A storage agnostic caching framework.
143
+ email:
144
+ - shogun_panda@me.com
145
+ executables: []
146
+ extensions: []
147
+ extra_rdoc_files: []
148
+ files:
149
+ - .gitignore
150
+ - .travis.yml
151
+ - .yardopts
152
+ - Gemfile
153
+ - README.md
154
+ - Rakefile
155
+ - doc/Elephas.html
156
+ - doc/Elephas/Cache.html
157
+ - doc/Elephas/Entry.html
158
+ - doc/Elephas/Exceptions.html
159
+ - doc/Elephas/Providers.html
160
+ - doc/Elephas/Providers/Base.html
161
+ - doc/Elephas/Providers/Hash.html
162
+ - doc/Elephas/Providers/RubyOnRails.html
163
+ - doc/Elephas/Version.html
164
+ - doc/_index.html
165
+ - doc/class_list.html
166
+ - doc/css/common.css
167
+ - doc/css/full_list.css
168
+ - doc/css/style.css
169
+ - doc/file.README.html
170
+ - doc/file_list.html
171
+ - doc/frames.html
172
+ - doc/index.html
173
+ - doc/js/app.js
174
+ - doc/js/full_list.js
175
+ - doc/js/jquery.js
176
+ - doc/method_list.html
177
+ - doc/top-level-namespace.html
178
+ - elephas.gemspec
179
+ - lib/elephas.rb
180
+ - lib/elephas/cache.rb
181
+ - lib/elephas/entry.rb
182
+ - lib/elephas/provider.rb
183
+ - lib/elephas/providers/hash.rb
184
+ - lib/elephas/providers/ruby_on_rails.rb
185
+ - lib/elephas/version.rb
186
+ - spec/coverage_helper.rb
187
+ - spec/elephas/cache_spec.rb
188
+ - spec/elephas/entry_spec.rb
189
+ - spec/elephas/provider_spec.rb
190
+ - spec/elephas/providers/hash_spec.rb
191
+ - spec/elephas/providers/ruby_on_rails_spec.rb
192
+ - spec/spec_helper.rb
193
+ homepage: http://github.com/ShogunPanda/elephas
194
+ licenses: []
195
+ post_install_message:
196
+ rdoc_options: []
197
+ require_paths:
198
+ - lib
199
+ required_ruby_version: !ruby/object:Gem::Requirement
200
+ none: false
201
+ requirements:
202
+ - - ! '>='
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ segments:
206
+ - 0
207
+ hash: 2608788952293416880
208
+ required_rubygems_version: !ruby/object:Gem::Requirement
209
+ none: false
210
+ requirements:
211
+ - - ! '>='
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ segments:
215
+ - 0
216
+ hash: 2608788952293416880
217
+ requirements: []
218
+ rubyforge_project: elephas
219
+ rubygems_version: 1.8.24
220
+ signing_key:
221
+ specification_version: 3
222
+ summary: A storage agnostic caching framework.
223
+ test_files:
224
+ - spec/coverage_helper.rb
225
+ - spec/elephas/cache_spec.rb
226
+ - spec/elephas/entry_spec.rb
227
+ - spec/elephas/provider_spec.rb
228
+ - spec/elephas/providers/hash_spec.rb
229
+ - spec/elephas/providers/ruby_on_rails_spec.rb
230
+ - spec/spec_helper.rb
231
+ has_rdoc: