record_redis 0.11.0 → 0.12.0

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTcyZmY2ZDAwYWZmZTAyZDJiODFlNDJiYjhlZTAxZDY5ZDU0OWFkNg==
4
+ Y2QyMTdjMzNjMzcxMTQ2ZmNmYmQwM2NjN2JlZGVkNjMwMDczNDJiNQ==
5
5
  data.tar.gz: !binary |-
6
- MTM2MDZlYzgyZTc1OGI3MTg5MTU1YzcwNTkxYmRhZmU1MzYwNzc0OQ==
6
+ MDBhMGE0Njc4YjFjODYyNGE1ZWYzOGNhYmFhMjk0MmQ2ODJjNGY1Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDEwY2FiNDU5MmViZTNkYTY3MzY1NDRjZDQ1MGI1NjA2ZmIwNzZmYjIyN2M2
10
- NmU3MzU5NDg3MzIyZjlkYWJjZDU0OTcwZTdmNGJlOTE1M2ExNzM1OWY0NDMy
11
- ZDhjMjg4NGE0ZTg4Mjg4OTViOWQwZGI4MzY3ZGM2MzBlNjFkODE=
9
+ NWY3MTQ4NTJiYzc5YmRiNTg1MjUzNmQwYWM2N2M1ODE3ZjVkYzQ0NDQ4ZmJm
10
+ ZWQ1OGEyNDNhMDQ4ZWM2ZDgwMzg2ODg1YmU0NGJkZWE5NGVkMDQwYzFhZmZi
11
+ MzljZjQ4NDNlYzU2MGNhYjI0MWE5YmYxOWUwOGE5N2I3NmRhY2M=
12
12
  data.tar.gz: !binary |-
13
- NzIyYTZiMDE3ZDkxNDJjYjhhZWIwNGU1MTFiOWY1OWJhMzFhYzQ3Yjk2OGQy
14
- YmQxYTNiNjVmNTZhODk5MWI3ZGFhYzg1NmQ2MGM0MTI4MGNjOWVjZDNlZWFk
15
- ODhjZjA3ZGM1Yjc0Y2JjYWYwZmY0MzI2ZmFmZjBjOGVhZTdmNTM=
13
+ ZWNjM2ViMmRkYzNiZWVhZTQzZjUxNTQ0NzhhYmEzYzA1NDMxYWMwNDljZjIz
14
+ ODhlOGRhY2FjYTY3ZDAyM2EyNWQ1YjljZTA4NmExMDMwY2ZmODEwZjkwMjA0
15
+ Yjg4ODdmYjcyY2I1MDc1OGFkZGM3MGE0OGMyZjcxNDZkNjAxYzM=
@@ -47,13 +47,13 @@ module RedisRecord
47
47
  def self.redis_sort(elements,order)
48
48
  attribute= order.split(" ").first
49
49
  direction= order.split(" ").last
50
-
50
+ result = Array.new
51
51
  if direction=="dsc"
52
- elements.sort {|a,b| b.send(attribute) <=> a.send(attribute)}
52
+ result= elements.sort {|a,b| b.send(attribute) <=> a.send(attribute)}
53
53
  else
54
- elements.sort {|a,b| a.send(attribute) <=> b.send(attribute)}
54
+ result= elements.sort {|a,b| a.send(attribute) <=> b.send(attribute)}
55
55
  end
56
-
56
+ result
57
57
 
58
58
  end
59
59
  def update(attributes)
@@ -126,12 +126,15 @@ module RedisRecord
126
126
 
127
127
  def self.make_all_selectors(name)
128
128
  class_eval <<-EOD
129
- def self.find_all_by_#{name}(value)
129
+ def self.find_all_by_#{name}(value,*args)
130
130
  models= Array.new
131
131
  results= self.find_all
132
132
  results.each do |result|
133
133
  models << result if result.#{name}==value
134
134
  end
135
+ if args.size > 0
136
+ models = redis_sort(models,args.first[:sort]) if args.first[:sort]
137
+ end
135
138
  models
136
139
  end
137
140
  EOD
@@ -1,3 +1,3 @@
1
1
  module RedisRecord
2
- VERSION = "0.11.0"
2
+ VERSION = "0.12.0"
3
3
  end
@@ -5,4 +5,9 @@ one:
5
5
  two:
6
6
  Name: s_name
7
7
  Format: s_format
8
- Key: s_key
8
+ Key: s_key
9
+
10
+ three:
11
+ Name: x_name
12
+ Format: s_format
13
+ Key: x_key
@@ -65,15 +65,28 @@ describe RedisRecord::Base do
65
65
  result= Network.find_by_Name("f_name")
66
66
  result.Name.should == name
67
67
  end
68
+
68
69
  end
69
70
 
70
71
  describe '#find_all_by_' do
72
+
73
+ before(:all) do
74
+ redis_fixture= RedisRecord::Fixture.new
75
+ redis_fixture.fixture "Network"
76
+ end
77
+
71
78
  it 'must find all Entries for the given attribute' do
72
79
  Network.create({"Name" => "testNetwork", "Key" => "t1"})
73
80
  Network.create({"Name" => "testNetwork", "Key" => "tt1"})
74
81
  results= Network.find_all_by_Name("testNetwork")
75
82
  results.size.should == 2
76
83
  end
84
+
85
+ it 'must return as first Entry with the given format and sort order a Network with name s_name' do
86
+ networks= Network.find_all_by_Format("s_format",:order => "Name asc")
87
+ networks.first.Name.should == "s_name"
88
+ end
89
+
77
90
  end
78
91
 
79
92
  describe '#update' do
@@ -94,12 +107,14 @@ describe RedisRecord::Base do
94
107
 
95
108
  describe '#find_all with sort' do
96
109
 
97
- redis_fixture= RedisRecord::Fixture.new
98
- redis_fixture.fixture "Network"
110
+ before(:all) do
111
+ redis_fixture= RedisRecord::Fixture.new
112
+ redis_fixture.fixture "Network"
113
+ end
99
114
 
100
115
  it 'must find all Entries for the given attribute sort by a attribute' do
101
116
  networks = Network.find_all({:sort => "Name dsc"})
102
- networks.first.Name.should == "s_name"
117
+ networks.first.Name.should == "x_name"
103
118
  end
104
119
 
105
120
  end
@@ -21,7 +21,7 @@ describe RedisRecord::Fixture do
21
21
  it 'should update a redis hash key by a fixture' do
22
22
  redis_fixture= RedisRecord::Fixture.new
23
23
  redis_fixture.fixture "Network"
24
- Network.find_all.size.should == 2
24
+ Network.find_all.size.should == 3
25
25
  end
26
26
 
27
27
  end
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.11.0
4
+ version: 0.12.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-31 00:00:00.000000000 Z
11
+ date: 2014-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis