remember 0.0.2 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/remember.rb +25 -43
- metadata +58 -49
- data/README.md +0 -53
- data/Rakefile +0 -23
- data/VERSION +0 -1
- data/doc/remember.jpg +0 -0
- data/spec/remember_spec.rb +0 -131
data/lib/remember.rb
CHANGED
@@ -1,56 +1,38 @@
|
|
1
|
-
require
|
1
|
+
require "forwardable"
|
2
|
+
require "moneta"
|
2
3
|
|
3
4
|
class Remember
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
attr_accessor :moneta
|
8
|
+
def_delegators :moneta, :clear, :key?, :has_key?
|
9
|
+
|
10
|
+
def initialize(moneta)
|
11
|
+
self.moneta = moneta
|
10
12
|
end
|
11
13
|
|
12
14
|
def store(key, object, options = {})
|
13
|
-
|
14
|
-
object
|
15
|
+
object.tap { |value| moneta.store(key, Marshal.dump(value), options) }
|
15
16
|
end
|
16
17
|
|
17
|
-
def
|
18
|
-
|
19
|
-
@moneta.update_key(key, options)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def fetch(key, options, &block)
|
24
|
-
if value = self[key]
|
25
|
-
value
|
26
|
-
else
|
27
|
-
store(key, yield, options)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def [](key)
|
32
|
-
deserialize(@moneta[key])
|
18
|
+
def get(key)
|
19
|
+
deserialize(moneta[key])
|
33
20
|
end
|
34
21
|
|
35
22
|
def delete(key)
|
36
|
-
deserialize(
|
37
|
-
end
|
38
|
-
|
39
|
-
def key?(key)
|
40
|
-
@moneta.key?(key)
|
23
|
+
deserialize(moneta.delete(key))
|
41
24
|
end
|
42
|
-
|
43
|
-
def
|
44
|
-
|
25
|
+
|
26
|
+
def fetch(key, options = {}, &block)
|
27
|
+
get(key) || store(key, yield, options)
|
45
28
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
29
|
+
|
30
|
+
alias_method :[], :get
|
31
|
+
alias_method :[]=, :store
|
32
|
+
|
49
33
|
private
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
34
|
+
|
35
|
+
def deserialize(value)
|
36
|
+
Marshal.load(value) if value && value.size > 0
|
37
|
+
end
|
38
|
+
end
|
metadata
CHANGED
@@ -1,69 +1,78 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: remember
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
|
-
authors:
|
7
|
+
authors:
|
7
8
|
- John Pignata
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-11-14 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: moneta
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
- !ruby/object:Gem::Version
|
16
|
+
requirement: &70188720542740 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
23
21
|
version: 0.6.0
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70188720542740
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &70188720542160 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.9.2
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70188720542160
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &70188720541640 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.7.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70188720541640
|
47
|
+
description: Quick hack to build quick persistence between application instances
|
48
|
+
email: john@pignata.com
|
27
49
|
executables: []
|
28
|
-
|
29
50
|
extensions: []
|
30
|
-
|
31
|
-
|
32
|
-
- README.md
|
33
|
-
files:
|
34
|
-
- README.md
|
35
|
-
- Rakefile
|
36
|
-
- VERSION
|
37
|
-
- doc/remember.jpg
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
38
53
|
- lib/remember.rb
|
39
|
-
- spec/remember_spec.rb
|
40
|
-
has_rdoc: true
|
41
54
|
homepage: http://github.com/jpignata/remember
|
42
55
|
licenses: []
|
43
|
-
|
44
56
|
post_install_message:
|
45
|
-
rdoc_options:
|
46
|
-
|
47
|
-
require_paths:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
48
59
|
- lib
|
49
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
61
72
|
requirements: []
|
62
|
-
|
63
73
|
rubyforge_project:
|
64
|
-
rubygems_version: 1.
|
74
|
+
rubygems_version: 1.8.10
|
65
75
|
signing_key:
|
66
76
|
specification_version: 3
|
67
77
|
summary: A Moneta wrapper for Ruby object persistence
|
68
|
-
test_files:
|
69
|
-
- spec/remember_spec.rb
|
78
|
+
test_files: []
|
data/README.md
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
# Remember
|
2
|
-
|
3
|
-
![Remember](/jpignata/remember/raw/master/doc/remember.jpg)
|
4
|
-
|
5
|
-
A simple object persistence wrapper for Moneta. Initialize Remember with any Moneta adapter and serialize any object that implements Ruby's marshal API.
|
6
|
-
|
7
|
-
## Adapters
|
8
|
-
|
9
|
-
Moneta currently supports:
|
10
|
-
|
11
|
-
* File store for xattr
|
12
|
-
* Basic File Store
|
13
|
-
* Memcache store
|
14
|
-
* In-memory store
|
15
|
-
* The xattrs in a file system
|
16
|
-
* DataMapper
|
17
|
-
* S3
|
18
|
-
* Berkeley DB
|
19
|
-
* Redis
|
20
|
-
* SDBM
|
21
|
-
* Tokyo
|
22
|
-
* CouchDB
|
23
|
-
|
24
|
-
## Usage
|
25
|
-
|
26
|
-
jp@populuxe:~/Projects/remember$ irb -r 'lib/remember' -r 'moneta/redis'
|
27
|
-
>> r = Remember.new(Moneta::Redis)
|
28
|
-
>> r["important_data"] = rand(100000000000000000000000)
|
29
|
-
=> 99924367975800373618177
|
30
|
-
>> r["important_data"]
|
31
|
-
=> 99924367975800373618177
|
32
|
-
>> r["config"] = { :setting => 'value', :other_setting => 'other value' }
|
33
|
-
|
34
|
-
jp@populuxe:~/Projects/remember$ irb -r 'lib/remember' -r 'moneta/redis'
|
35
|
-
>> r = Remember.new(Moneta::Redis)
|
36
|
-
>> r["important_data"]
|
37
|
-
=> 99924367975800373618177
|
38
|
-
>> r["config"]
|
39
|
-
=> {:setting=>"value", :other_setting=>"other value"}
|
40
|
-
|
41
|
-
jp@populuxe:~/Projects/remember$ irb -r 'lib/remember' -r 'moneta/redis'
|
42
|
-
>> r = Remember.new(Moneta::Redis)
|
43
|
-
>> class Duck; def make_noise; "Quack!"; end; end
|
44
|
-
>> d = Duck.new
|
45
|
-
>> d.make_noise
|
46
|
-
=> "Quack!"
|
47
|
-
>> r["duck"] = d
|
48
|
-
|
49
|
-
jp@populuxe:~/Projects/remember$ irb -r 'lib/remember' -r 'moneta/redis'
|
50
|
-
>> r = Remember.new(Moneta::Redis)
|
51
|
-
>> class Duck; def make_noise; "Quack!"; end; end
|
52
|
-
>> r["duck"].make_noise
|
53
|
-
=> "Quack!"
|
data/Rakefile
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'spec/rake/spectask'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gemspec|
|
7
|
-
gemspec.name = "remember"
|
8
|
-
gemspec.summary = "A Moneta wrapper for Ruby object persistence"
|
9
|
-
gemspec.description = "A Moneta wrapper for Ruby object persistence"
|
10
|
-
gemspec.email = "john.pignata@gmail.com"
|
11
|
-
gemspec.homepage = "http://github.com/jpignata/remember"
|
12
|
-
gemspec.authors = ["John Pignata"]
|
13
|
-
gemspec.add_dependency("moneta", "0.6.0")
|
14
|
-
end
|
15
|
-
Jeweler::GemcutterTasks.new
|
16
|
-
rescue LoadError
|
17
|
-
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
18
|
-
end
|
19
|
-
|
20
|
-
Spec::Rake::SpecTask.new(:spec) do |t|
|
21
|
-
t.spec_files = FileList['spec/*_spec.rb']
|
22
|
-
t.spec_opts = ['--color', '--format specdoc']
|
23
|
-
end
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.2
|
data/doc/remember.jpg
DELETED
Binary file
|
data/spec/remember_spec.rb
DELETED
@@ -1,131 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../lib/remember')
|
2
|
-
require 'moneta/memory'
|
3
|
-
|
4
|
-
describe Remember do
|
5
|
-
before do
|
6
|
-
@r = Remember.new(Moneta::Memory)
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "#[]=" do
|
10
|
-
it "returns the Object originally passed into it" do
|
11
|
-
@r["enum_sizes"] = ['xs', 's', 'm', 'l'].should == ['xs', 's', 'm', 'l']
|
12
|
-
end
|
13
|
-
|
14
|
-
it "persists object values and behaviors" do
|
15
|
-
class Bridge < Struct.new(:name, :year)
|
16
|
-
def to_s; "#{name} opened in #{year}"; end
|
17
|
-
def opened?; year < Time.now.year; end
|
18
|
-
end
|
19
|
-
|
20
|
-
@r["brooklyn"] = Bridge.new("Brooklyn Bridge", 1883)
|
21
|
-
@r["verrazano"] = Bridge.new("Verrazano-Narrows Bridge", 1964)
|
22
|
-
|
23
|
-
@r["brooklyn"].to_s.should == "Brooklyn Bridge opened in 1883"
|
24
|
-
@r["verrazano"].year.should == 1964
|
25
|
-
@r["brooklyn"].opened?.should be_true
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#[]" do
|
30
|
-
context "a given key exists" do
|
31
|
-
it "returns a deserialized object" do
|
32
|
-
@r["thirteen"] = 13
|
33
|
-
@r["thirteen"].should == 13
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "a given key does not exist" do
|
38
|
-
it "returns nil" do
|
39
|
-
@r["pretend"].should be_nil
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "#delete" do
|
45
|
-
context "a given key exists" do
|
46
|
-
it "returns the object that the key contained after deletion" do
|
47
|
-
@r["thirteen"] = 13
|
48
|
-
@r.delete("thirteen").should == 13
|
49
|
-
@r["thirteen"].should be_nil
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context "a given key does not exist" do
|
54
|
-
it "returns nil" do
|
55
|
-
@r.delete("pretend").should be_nil
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "#key?" do
|
61
|
-
context "a key that exists" do
|
62
|
-
it "returns true" do
|
63
|
-
@r["real"] = true
|
64
|
-
@r.key?("real").should be_true
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context "a key that does not exist" do
|
69
|
-
it "returns false" do
|
70
|
-
@r.key?("pretend").should be_false
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe "#has_key?" do
|
76
|
-
it "is an alias for key?" do
|
77
|
-
@r.has_key?("pretend").should == @r.key?("pretend")
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe "#clear" do
|
82
|
-
it "clears all persisted objects" do
|
83
|
-
@r["do"] = 1
|
84
|
-
@r["ray"] = 2
|
85
|
-
@r["egon"] = 3
|
86
|
-
@r.clear
|
87
|
-
@r.key?("ray").should be_false
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "#store" do
|
92
|
-
it "saves an object to key and sets an expiration in seconds" do
|
93
|
-
@r.store("zuul", :zuul, :expires_in => 60).should == :zuul
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "#update_key" do
|
98
|
-
context "a key that exists" do
|
99
|
-
it "updates object identified by key and sets an expiration in seconds and returns the new expiration time" do
|
100
|
-
@r["gozer"] = :gozer
|
101
|
-
@r.update_key("gozer", :expires_in => 60).to_i.should == Time.now.to_i + 60
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context "a key that does not exist" do
|
106
|
-
it "returns nil" do
|
107
|
-
@r.update_key("slimer", :expires_in => 60).should be_nil
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe "#fetch" do
|
113
|
-
context "a key that exists" do
|
114
|
-
it "fetches the object" do
|
115
|
-
@r["some_data"] = 123
|
116
|
-
@r.fetch("some_data", :expires_in => 120) { 456 }.should == 123
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context "a key that does not exist" do
|
121
|
-
it "executes a block and then stores the resulting object" do
|
122
|
-
@r["resource_intensive_data"].should be_nil
|
123
|
-
data = @r.fetch("resource_intensive_data", :expires_in => 120) do
|
124
|
-
['calculation']
|
125
|
-
end
|
126
|
-
data.should == ['calculation']
|
127
|
-
@r["resource_intensive_data"].should == ['calculation']
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|