record_redis 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/lib/redis_record/base.rb +16 -1
- data/lib/redis_record/relation.rb +2 -2
- data/lib/redis_record/version.rb +1 -1
- data/spec/lib/redis_record/base_spec.rb +26 -7
- data/spec/lib/redis_record/config_spec.rb +4 -4
- data/spec/lib/redis_record/fixture_spec.rb +0 -4
- data/spec/lib/redis_record/relation_spec.rb +4 -2
- data/spec/spec_helper.rb +2 -2
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTcyZmY2ZDAwYWZmZTAyZDJiODFlNDJiYjhlZTAxZDY5ZDU0OWFkNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTM2MDZlYzgyZTc1OGI3MTg5MTU1YzcwNTkxYmRhZmU1MzYwNzc0OQ==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZDEwY2FiNDU5MmViZTNkYTY3MzY1NDRjZDQ1MGI1NjA2ZmIwNzZmYjIyN2M2
|
10
|
+
NmU3MzU5NDg3MzIyZjlkYWJjZDU0OTcwZTdmNGJlOTE1M2ExNzM1OWY0NDMy
|
11
|
+
ZDhjMjg4NGE0ZTg4Mjg4OTViOWQwZGI4MzY3ZGM2MzBlNjFkODE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NzIyYTZiMDE3ZDkxNDJjYjhhZWIwNGU1MTFiOWY1OWJhMzFhYzQ3Yjk2OGQy
|
14
|
+
YmQxYTNiNjVmNTZhODk5MWI3ZGFhYzg1NmQ2MGM0MTI4MGNjOWVjZDNlZWFk
|
15
|
+
ODhjZjA3ZGM1Yjc0Y2JjYWYwZmY0MzI2ZmFmZjBjOGVhZTdmNTM=
|
data/lib/redis_record/base.rb
CHANGED
@@ -21,7 +21,7 @@ module RedisRecord
|
|
21
21
|
model
|
22
22
|
end
|
23
23
|
|
24
|
-
def self.find_all
|
24
|
+
def self.find_all(*args)
|
25
25
|
models = Array.new
|
26
26
|
name= self.name
|
27
27
|
RedisRecord::Connection.connect unless RedisRecord::Connection.isConnected?
|
@@ -38,9 +38,24 @@ module RedisRecord
|
|
38
38
|
else
|
39
39
|
return nil
|
40
40
|
end
|
41
|
+
if args.size > 0
|
42
|
+
models = redis_sort(models,args.first[:sort]) if args.first[:sort]
|
43
|
+
end
|
41
44
|
models
|
42
45
|
end
|
43
46
|
|
47
|
+
def self.redis_sort(elements,order)
|
48
|
+
attribute= order.split(" ").first
|
49
|
+
direction= order.split(" ").last
|
50
|
+
|
51
|
+
if direction=="dsc"
|
52
|
+
elements.sort {|a,b| b.send(attribute) <=> a.send(attribute)}
|
53
|
+
else
|
54
|
+
elements.sort {|a,b| a.send(attribute) <=> b.send(attribute)}
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
end
|
44
59
|
def update(attributes)
|
45
60
|
@hash_of_properties.merge!(attributes)
|
46
61
|
name= self.class
|
@@ -25,7 +25,7 @@ module RedisRecord
|
|
25
25
|
def self.make_has_many_relation(name)
|
26
26
|
class_eval <<-EOD
|
27
27
|
def #{name}
|
28
|
-
#{name}.find_all_by_#{self.name}Key(self.Key)
|
28
|
+
#{name}.find_all_by_#{self.name}Key(self.Key.to_s)
|
29
29
|
end
|
30
30
|
EOD
|
31
31
|
end
|
@@ -40,7 +40,7 @@ module RedisRecord
|
|
40
40
|
def self.make_has_one_relation(name)
|
41
41
|
class_eval <<-EOD
|
42
42
|
def #{name}
|
43
|
-
#{name}.find_by_#{self.name}Key(self.Key)
|
43
|
+
#{name}.find_by_#{self.name}Key(self.Key.to_s)
|
44
44
|
end
|
45
45
|
EOD
|
46
46
|
end
|
data/lib/redis_record/version.rb
CHANGED
@@ -2,11 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe RedisRecord::Base do
|
4
4
|
|
5
|
+
|
5
6
|
describe '#properties' do
|
6
7
|
it 'should have a method #name and #format' do
|
7
8
|
network= Network.new
|
8
|
-
network.methods.to_s.include?("Name=").should
|
9
|
-
network.methods.to_s.include?("Format=").should
|
9
|
+
network.methods.to_s.include?("Name=").should == true
|
10
|
+
network.methods.to_s.include?("Format=").should == true
|
10
11
|
end
|
11
12
|
|
12
13
|
it 'must change the value of the name property' do
|
@@ -20,13 +21,13 @@ describe RedisRecord::Base do
|
|
20
21
|
describe '#create' do
|
21
22
|
it 'should should be true to create a entity' do
|
22
23
|
network= Network.create({"Name" => "paul"})
|
23
|
-
network.should
|
24
|
+
network.should == true
|
24
25
|
|
25
26
|
end
|
26
27
|
|
27
28
|
it 'should be true to create a entity with empty key' do
|
28
29
|
network= Network.create({"Name" => "paul", "Key" => ""})
|
29
|
-
network.should
|
30
|
+
network.should == true
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
@@ -53,9 +54,15 @@ describe RedisRecord::Base do
|
|
53
54
|
end
|
54
55
|
|
55
56
|
describe '#find_by_' do
|
57
|
+
|
58
|
+
before(:all) do
|
59
|
+
redis_fixture= RedisRecord::Fixture.new
|
60
|
+
redis_fixture.fixture "Network"
|
61
|
+
end
|
62
|
+
|
56
63
|
it 'must find a Entry with the given name' do
|
57
|
-
name= "
|
58
|
-
result= Network.find_by_Name("
|
64
|
+
name= "f_name"
|
65
|
+
result= Network.find_by_Name("f_name")
|
59
66
|
result.Name.should == name
|
60
67
|
end
|
61
68
|
end
|
@@ -81,7 +88,19 @@ describe RedisRecord::Base do
|
|
81
88
|
it 'should remove a existing entity' do
|
82
89
|
Network.create({"Name" => "paul", "Key" => "1234567890_for_delete"})
|
83
90
|
network= Network.find("1234567890_for_delete")
|
84
|
-
network.delete.should
|
91
|
+
network.delete.should == 1
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#find_all with sort' do
|
96
|
+
|
97
|
+
redis_fixture= RedisRecord::Fixture.new
|
98
|
+
redis_fixture.fixture "Network"
|
99
|
+
|
100
|
+
it 'must find all Entries for the given attribute sort by a attribute' do
|
101
|
+
networks = Network.find_all({:sort => "Name dsc"})
|
102
|
+
networks.first.Name.should == "s_name"
|
85
103
|
end
|
104
|
+
|
86
105
|
end
|
87
106
|
end
|
@@ -4,7 +4,7 @@ describe RedisRecord::Connection do
|
|
4
4
|
before (:all) do
|
5
5
|
@host = "127.0.0.1"
|
6
6
|
@port = "6379"
|
7
|
-
@db =
|
7
|
+
@db = 2
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'must set a host for a connection' do
|
@@ -23,20 +23,20 @@ describe RedisRecord::Connection do
|
|
23
23
|
describe '#connect' do
|
24
24
|
it 'has to connect to a given redis db' do
|
25
25
|
redis = RedisRecord::Connection.connect
|
26
|
-
RedisRecord::Connection.isConnected?.should
|
26
|
+
RedisRecord::Connection.isConnected?.should == true
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'has to reconnect to a given redis db' do
|
30
30
|
redis = RedisRecord::Connection.connect
|
31
31
|
redis.client.disconnect
|
32
32
|
redis = RedisRecord::Connection.connect
|
33
|
-
RedisRecord::Connection.isConnected?.should
|
33
|
+
RedisRecord::Connection.isConnected?.should == true
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'should be false to check a failed redis connection' do
|
37
37
|
redis = RedisRecord::Connection.connect
|
38
38
|
redis.client.disconnect
|
39
|
-
RedisRecord::Connection.isConnected?.should
|
39
|
+
RedisRecord::Connection.isConnected?.should == false
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -6,10 +6,6 @@ describe RedisRecord::Fixture do
|
|
6
6
|
#code
|
7
7
|
end
|
8
8
|
|
9
|
-
before(:all) do
|
10
|
-
RedisRecord::Fixture::Fixture_Path= "./spec/fixtures/"
|
11
|
-
end
|
12
|
-
|
13
9
|
it 'should load a fixtures yaml' do
|
14
10
|
fixture= RedisRecord::Fixture.new
|
15
11
|
erg = fixture.load(RedisRecord::Fixture::Fixture_Path+"network")
|
@@ -13,12 +13,14 @@ end
|
|
13
13
|
describe RedisRecord::Base do
|
14
14
|
|
15
15
|
it 'Site must have a Network' do
|
16
|
-
network= Network.create({
|
17
|
-
site= Site.create({
|
16
|
+
network= Network.create({"Name" => "paul", "Key" => "1234567890"})
|
17
|
+
site= Site.create({"Name" => "paul", "Key" => "1234567890", "NetworkKey"=>"1234567890"})
|
18
18
|
site= Site.find("1234567890")
|
19
19
|
site.Network.Name.should=="paul"
|
20
20
|
end
|
21
21
|
it 'Network must have a Site' do
|
22
|
+
network= Network.create({"Name" => "paul", "Key" => "1234567890"})
|
23
|
+
Site.create({"Name" => "paul", "Key" => "1234567890", "NetworkKey"=>"1234567890"})
|
22
24
|
network= Network.find("1234567890")
|
23
25
|
network.Site.first.Name.should=="paul"
|
24
26
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: record_redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcel Schlimper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -28,42 +28,42 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ! '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ! '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: a redis orm mapper for rails
|
@@ -73,8 +73,8 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
-
|
77
|
-
-
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
78
|
- Gemfile
|
79
79
|
- LICENSE.txt
|
80
80
|
- README.md
|
@@ -103,12 +103,12 @@ require_paths:
|
|
103
103
|
- lib
|
104
104
|
required_ruby_version: !ruby/object:Gem::Requirement
|
105
105
|
requirements:
|
106
|
-
- -
|
106
|
+
- - ! '>='
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
110
|
requirements:
|
111
|
-
- -
|
111
|
+
- - ! '>='
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|