active_redis_orm 0.0.6 → 0.0.7
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/lib/active_redis/attributes.rb +1 -1
- data/lib/active_redis/version.rb +1 -1
- data/lib/active_redis_orm.rb +5 -1
- data/spec/lib/active_redis_spec.rb +10 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c05be7c5fafe7f5194a6dfe7d3662cc05173a3e0
|
4
|
+
data.tar.gz: 9b33a859fb406fa9ae081b9fe02ed63198a3b0e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 707db972bd38d28f098babdfc36dadd05a2be22bb707a607ed9789d3b45c121f7894e4dc391ed3f3d78722b93b944b14dde4e45334486a79771d0040459e0c58
|
7
|
+
data.tar.gz: 446768c2dcebcde98d8356902ff0db0a6c97a329ed6873adb9bfa11a4f713aaadba98cd3ddcb1d5bcb13e2a125451a443c8c7e539d2f5f12faac78225bda7c60
|
@@ -445,7 +445,7 @@ module ActiveRedis
|
|
445
445
|
|
446
446
|
class_eval %Q{
|
447
447
|
def self.find_by_#{field_name}(value)
|
448
|
-
id = Redis.current.get(finder_key(
|
448
|
+
id = Redis.current.get(finder_key(:#{field_name}, value))
|
449
449
|
if id.present?
|
450
450
|
self.find(id)
|
451
451
|
else
|
data/lib/active_redis/version.rb
CHANGED
data/lib/active_redis_orm.rb
CHANGED
@@ -92,7 +92,11 @@ module ActiveRedis
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def finder_key(field_name, value)
|
95
|
-
|
95
|
+
if attribute_options[field_name] && attribute_options[field_name][:finder_key].present?
|
96
|
+
attribute_options[field_name][:finder_key].call(value)
|
97
|
+
else
|
98
|
+
"#{redis_namespace.pluralize}:#{field_name}_to_#{redis_namespace}_id:#{value}"
|
99
|
+
end
|
96
100
|
end
|
97
101
|
|
98
102
|
def attributes
|
@@ -2,7 +2,7 @@ require "active_redis_orm"
|
|
2
2
|
|
3
3
|
describe ActiveRedis do
|
4
4
|
class ActiveRedisObject < ActiveRedis::Base
|
5
|
-
attr_accessible :foo, :bar, :list, :set, :sorted_set, :hash, :expired_field, :date, :time
|
5
|
+
attr_accessible :foo, :bar, :list, :set, :sorted_set, :hash, :expired_field, :date, :time, :custom_finder
|
6
6
|
|
7
7
|
field :foo, type: :string
|
8
8
|
field :bar, finder_field: true
|
@@ -14,6 +14,7 @@ describe ActiveRedis do
|
|
14
14
|
field :bool, type: :boolean
|
15
15
|
field :date, type: :date
|
16
16
|
field :time, type: :time
|
17
|
+
field :custom_finder, finder_field: true, finder_key: lambda{|value| "foo:bar:#{value}"}
|
17
18
|
|
18
19
|
list :all
|
19
20
|
list :all_with_bar, if: lambda{|object| object.bar.present? }
|
@@ -90,6 +91,14 @@ describe ActiveRedis do
|
|
90
91
|
ActiveRedisObject.find_by_bar("barbar").should be_blank
|
91
92
|
ActiveRedisObject.find_by_bar("baz").should == object
|
92
93
|
end
|
94
|
+
|
95
|
+
it "can be defined with a custom key" do
|
96
|
+
object = ActiveRedisObject.create(custom_finder: "wagamama")
|
97
|
+
|
98
|
+
Redis.current.get("foo:bar:wagamama").should == object.id
|
99
|
+
ActiveRedisObject.find_by_custom_finder("wagamama").should == object
|
100
|
+
ActiveRedisObject.find_by_custom_finder("wagamamaa").should be_blank
|
101
|
+
end
|
93
102
|
end
|
94
103
|
|
95
104
|
context "#dirty?" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_redis_orm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Caspy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|