dkastner-moneta 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/moneta/adapters/active_record.rb +39 -37
- data/lib/moneta/version.rb +1 -1
- data/spec/moneta_active_record_spec.rb +1 -1
- metadata +4 -4
@@ -5,53 +5,55 @@ rescue LoadError
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module Moneta
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
self.class.
|
8
|
+
module Adapters
|
9
|
+
class ActiveRecord
|
10
|
+
include Moneta::Defaults
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
@options = options
|
14
|
+
unless self.class.const_defined?('Store')
|
15
|
+
self.class.const_set('Store', Class.new(::ActiveRecord::Base)) # this prevents loading issues when active_record gem is unavailable
|
16
|
+
end
|
17
|
+
Store.establish_connection(@options[:connection] || raise("Must specify :connection"))
|
18
|
+
Store.set_table_name(@options[:table] || 'moneta_store')
|
15
19
|
end
|
16
|
-
Store.establish_connection(@options[:connection] || raise("Must specify :connection"))
|
17
|
-
Store.set_table_name(@options[:table] || 'moneta_store')
|
18
|
-
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
def migrate
|
22
|
+
unless Store.table_exists?
|
23
|
+
Store.connection.create_table Store.table_name, :id => false do |t|
|
24
|
+
t.string 'key', :primary => :true
|
25
|
+
t.string 'value'
|
26
|
+
end
|
25
27
|
end
|
26
28
|
end
|
27
|
-
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
def key?(key)
|
31
|
+
record = Store.find_by_key key_for(key)
|
32
|
+
!record.nil?
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
def [](key)
|
36
|
+
record = Store.find_by_key key_for(key)
|
37
|
+
record ? deserialize(record.value) : nil
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
def delete(key)
|
41
|
+
record = Store.find_by_key key_for(key)
|
42
|
+
if record
|
43
|
+
Store.where(:key => key_for(record.key)).delete_all
|
44
|
+
deserialize record.value
|
45
|
+
end
|
44
46
|
end
|
45
|
-
end
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
def store(key, value, options = {})
|
49
|
+
record = Store.new :key => key_for(key), :value => serialize(value)
|
50
|
+
record.save!
|
51
|
+
value
|
52
|
+
end
|
52
53
|
|
53
|
-
|
54
|
-
|
54
|
+
def clear
|
55
|
+
Store.delete_all
|
56
|
+
end
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
data/lib/moneta/version.rb
CHANGED
@@ -5,7 +5,7 @@ require 'moneta/adapters/active_record'
|
|
5
5
|
if defined?(ActiveRecord)
|
6
6
|
describe 'Moneta::ActiveRecord' do
|
7
7
|
before(:each) do
|
8
|
-
@cache = Moneta::ActiveRecord.new(:connection => {
|
8
|
+
@cache = Moneta::Adapters::ActiveRecord.new(:connection => {
|
9
9
|
:adapter => 'sqlite3',
|
10
10
|
:database => 'reports_test.sqlite3'
|
11
11
|
})
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 1
|
9
|
+
version: 1.0.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Yehuda Katz
|
@@ -136,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
136
|
requirements:
|
137
137
|
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
hash: -
|
139
|
+
hash: -3802511716438480578
|
140
140
|
segments:
|
141
141
|
- 0
|
142
142
|
version: "0"
|
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
145
|
requirements:
|
146
146
|
- - ">="
|
147
147
|
- !ruby/object:Gem::Version
|
148
|
-
hash: -
|
148
|
+
hash: -3802511716438480578
|
149
149
|
segments:
|
150
150
|
- 0
|
151
151
|
version: "0"
|