redis_model 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Guardfile +51 -0
- data/lib/redis_model/attribute.rb +15 -0
- data/lib/redis_model/version.rb +1 -1
- data/redis_model.gemspec +3 -0
- data/spec/redis_model/attribute_spec.rb +46 -0
- data/spec/redis_model/types/base_spec.rb +1 -1
- data/spec/redis_model/types/set_spec.rb +1 -1
- data/spec/redis_model/types/sorted_set_spec.rb +5 -5
- data/spec/support/active_record.rb +5 -0
- data/spec/support/schema.rb +5 -0
- metadata +49 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fb4d160afa7d9fa830478c51ac1627684059245
|
4
|
+
data.tar.gz: e038641ca83e3a3fbd8024b4b02721a6179e3bca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1b8a0a541d27c7d2bbadf7d5e7677b956442ee75e25efdaee7d11870648925f0e64a76d068aab03e6c9390e407e347e48656fdadee1abd9cb43bfbb0e81a803
|
7
|
+
data.tar.gz: 057df964c16d69b200d0612a24e953fb64810183f17ae42ae6b583e3e2b2a5f622610c3743df95aa79a3421533a858fde4b990a416d2f07dd24124ce9c8e8f90
|
data/.gitignore
CHANGED
data/Guardfile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec feature)
|
6
|
+
|
7
|
+
## Uncomment to clear the screen before every task
|
8
|
+
# clearing :on
|
9
|
+
|
10
|
+
## Guard internally checks for changes in the Guardfile and exits.
|
11
|
+
## If you want Guard to automatically start up again, run guard in a
|
12
|
+
## shell loop, e.g.:
|
13
|
+
##
|
14
|
+
## $ while bundle exec guard; do echo "Restarting Guard..."; done
|
15
|
+
##
|
16
|
+
## Note: if you are using the `directories` clause above and you are not
|
17
|
+
## watching the project directory ('.'), the you will want to move the Guardfile
|
18
|
+
## to a watched dir and symlink it back, e.g.
|
19
|
+
#
|
20
|
+
# $ mkdir config
|
21
|
+
# $ mv Guardfile config/
|
22
|
+
# $ ln -s config/Guardfile .
|
23
|
+
#
|
24
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
25
|
+
|
26
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
27
|
+
# rspec may be run, below are examples of the most common uses.
|
28
|
+
# * bundler: 'bundle exec rspec'
|
29
|
+
# * bundler binstubs: 'bin/rspec'
|
30
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
31
|
+
# installed the spring binstubs per the docs)
|
32
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
33
|
+
# * 'just' rspec: 'rspec'
|
34
|
+
|
35
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
36
|
+
require "guard/rspec/dsl"
|
37
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
38
|
+
|
39
|
+
# Feel free to open issues for suggestions and improvements
|
40
|
+
|
41
|
+
# RSpec files
|
42
|
+
rspec = dsl.rspec
|
43
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
44
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
45
|
+
watch(rspec.spec_files)
|
46
|
+
|
47
|
+
# Ruby files
|
48
|
+
ruby = dsl.ruby
|
49
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
50
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
51
|
+
end
|
@@ -119,6 +119,21 @@ module RedisModel
|
|
119
119
|
|
120
120
|
def self.included(klass)
|
121
121
|
klass.extend ClassMethods
|
122
|
+
|
123
|
+
if klass.respond_to?(:after_destroy)
|
124
|
+
klass.after_destroy :clear_redis_model_attributes
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Public: Clears attributes defined by RedisModel.
|
129
|
+
#
|
130
|
+
# Returns nothing.
|
131
|
+
def clear_redis_model_attributes
|
132
|
+
RedisModel::Schema.collection.each do |klass, _|
|
133
|
+
if klass < RedisModel::BelongedTo && Object.const_get(klass.to_s.deconstantize) >= self.class
|
134
|
+
self.send(klass.to_s.demodulize.underscore).del
|
135
|
+
end
|
136
|
+
end
|
122
137
|
end
|
123
138
|
end
|
124
139
|
end
|
data/lib/redis_model/version.rb
CHANGED
data/redis_model.gemspec
CHANGED
@@ -25,4 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency 'rake'
|
26
26
|
spec.add_development_dependency 'rspec'
|
27
27
|
spec.add_development_dependency 'kaminari'
|
28
|
+
spec.add_development_dependency 'activerecord'
|
29
|
+
spec.add_development_dependency 'sqlite3'
|
30
|
+
spec.add_development_dependency 'guard'
|
28
31
|
end
|
@@ -9,6 +9,10 @@ class TestModel
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
class TestActiveRecordModel < ActiveRecord::Base
|
13
|
+
self.table_name = 'ar_model'
|
14
|
+
end
|
15
|
+
|
12
16
|
describe RedisModel::Attribute do
|
13
17
|
let(:parent_klass) { dynamic_class(TestModel) }
|
14
18
|
|
@@ -74,4 +78,46 @@ describe RedisModel::Attribute do
|
|
74
78
|
it { expect(definition_helper).to respond_to(:sorted_set) }
|
75
79
|
it { expect { definition_helper.counter :my_counter }.to change { parent_klass.new('test').methods } }
|
76
80
|
end
|
81
|
+
|
82
|
+
describe '#clear_redis_modeL_attributes' do
|
83
|
+
let(:parent_klass) { dynamic_class(TestModel) }
|
84
|
+
let(:attribute_name) { :my_counter }
|
85
|
+
let(:attribute_type) { :counter }
|
86
|
+
let(:test_id) { 'test' }
|
87
|
+
let(:object) { parent_klass.new(test_id) }
|
88
|
+
let(:redis_model_attribute) { object.send(attribute_name) }
|
89
|
+
|
90
|
+
context 'when current class defines the attribute' do
|
91
|
+
before { parent_klass.redis_model_attribute attribute_name, attribute_type }
|
92
|
+
before { redis_model_attribute.set(1) }
|
93
|
+
|
94
|
+
it { expect { object.clear_redis_model_attributes }.to change { RedisModel::Base.connection.get(redis_model_attribute.key_label) }.to(nil) }
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when parent class defines the attribute' do
|
98
|
+
let(:current_klass) { dynamic_class(parent_klass) }
|
99
|
+
let(:object) { current_klass.new(test_id) }
|
100
|
+
|
101
|
+
before { parent_klass.redis_model_attribute attribute_name, attribute_type }
|
102
|
+
before { redis_model_attribute.set(1) }
|
103
|
+
|
104
|
+
it { expect { object.clear_redis_model_attributes }.to change { RedisModel::Base.connection.get(redis_model_attribute.key_label) }.to(nil) }
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'when parent class is activerecord model' do
|
108
|
+
let(:parent_klass) { dynamic_class(TestActiveRecordModel) }
|
109
|
+
let(:object) { parent_klass.create }
|
110
|
+
|
111
|
+
before { parent_klass.redis_model_attribute attribute_name, attribute_type }
|
112
|
+
before { redis_model_attribute.set(1) }
|
113
|
+
|
114
|
+
context 'when it is cleared explicitly' do
|
115
|
+
it { expect { object.clear_redis_model_attributes }.to change { RedisModel::Base.connection.get(redis_model_attribute.key_label) }.to(nil) }
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'when it is invoked via activerecord callback' do
|
119
|
+
it { expect { object.destroy }.to change { RedisModel::Base.connection.get(redis_model_attribute.key_label) }.to(nil) }
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
77
123
|
end
|
@@ -8,7 +8,7 @@ describe RedisModel::Types::Base do
|
|
8
8
|
before { klass.send(:include, RedisModel::Types::Base) }
|
9
9
|
|
10
10
|
describe '#exists?' do
|
11
|
-
it { expect(object.exists?).to
|
11
|
+
it { expect(object.exists?).to eq(false) }
|
12
12
|
it { expect { RedisModel::Base.connection.set(object.key_label, 'value') }.to change { object.exists? } }
|
13
13
|
end
|
14
14
|
|
@@ -57,6 +57,6 @@ describe RedisModel::Types::Set do
|
|
57
57
|
|
58
58
|
before { elements.each { |element| RedisModel::Base.connection.sadd(object.key_label, element) } }
|
59
59
|
|
60
|
-
it { expect(object.pick(5).all? { |e| elements.include?(e) }).to
|
60
|
+
it { expect(object.pick(5).all? { |e| elements.include?(e) }).to eq(true) }
|
61
61
|
end
|
62
62
|
end
|
@@ -34,14 +34,14 @@ describe RedisModel::Types::SortedSet do
|
|
34
34
|
|
35
35
|
describe '#include?' do
|
36
36
|
context 'when sorted set does not exist' do
|
37
|
-
it { expect(object.include?(members.keys.first)).to
|
37
|
+
it { expect(object.include?(members.keys.first)).to eq(false) }
|
38
38
|
end
|
39
39
|
|
40
40
|
context 'when sorted set has been populated before' do
|
41
41
|
before { populate }
|
42
42
|
|
43
|
-
it { expect(object.include?(members.keys.first)).to
|
44
|
-
it { expect(object.include?('unknown key')).to
|
43
|
+
it { expect(object.include?(members.keys.first)).to eq(true) }
|
44
|
+
it { expect(object.include?('unknown key')).to eq(false) }
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -234,7 +234,7 @@ describe RedisModel::Types::SortedSet do
|
|
234
234
|
key_label = intersected.key_label
|
235
235
|
end
|
236
236
|
|
237
|
-
expect(RedisModel::Base.connection.exists(key_label)).to
|
237
|
+
expect(RedisModel::Base.connection.exists(key_label)).to eq(false)
|
238
238
|
end
|
239
239
|
|
240
240
|
context 'when seed is given' do
|
@@ -295,7 +295,7 @@ describe RedisModel::Types::SortedSet do
|
|
295
295
|
key_label = intersected.key_label
|
296
296
|
end
|
297
297
|
|
298
|
-
expect(RedisModel::Base.connection.exists(key_label)).to
|
298
|
+
expect(RedisModel::Base.connection.exists(key_label)).to eq(false)
|
299
299
|
end
|
300
300
|
end
|
301
301
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Inbeom Hwang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -94,6 +94,48 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activerecord
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sqlite3
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: guard
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
97
139
|
description: RedisModel provides various types of interfaces to handle values on Redis
|
98
140
|
email:
|
99
141
|
- hwanginbeom@gmail.com
|
@@ -103,6 +145,7 @@ extra_rdoc_files: []
|
|
103
145
|
files:
|
104
146
|
- ".gitignore"
|
105
147
|
- Gemfile
|
148
|
+
- Guardfile
|
106
149
|
- LICENSE.txt
|
107
150
|
- README.md
|
108
151
|
- Rakefile
|
@@ -145,7 +188,9 @@ files:
|
|
145
188
|
- spec/redis_model/types/string_spec.rb
|
146
189
|
- spec/redis_model/types/timestamp_spec.rb
|
147
190
|
- spec/spec_helper.rb
|
191
|
+
- spec/support/active_record.rb
|
148
192
|
- spec/support/dynamic_class.rb
|
193
|
+
- spec/support/schema.rb
|
149
194
|
homepage: http://gitlab.ultracaption.net/inbeom/redis_model
|
150
195
|
licenses:
|
151
196
|
- MIT
|
@@ -187,4 +232,6 @@ test_files:
|
|
187
232
|
- spec/redis_model/types/string_spec.rb
|
188
233
|
- spec/redis_model/types/timestamp_spec.rb
|
189
234
|
- spec/spec_helper.rb
|
235
|
+
- spec/support/active_record.rb
|
190
236
|
- spec/support/dynamic_class.rb
|
237
|
+
- spec/support/schema.rb
|