active-redis 0.0.2 → 0.1.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.
- data/lib/active-redis.rb +44 -5
- metadata +3 -3
data/lib/active-redis.rb
CHANGED
@@ -1,11 +1,38 @@
|
|
1
|
-
|
1
|
+
module ActiveRedis
|
2
2
|
|
3
|
-
|
3
|
+
def self.included(base)
|
4
|
+
base.send(:include, Paperclip::Resource)
|
5
|
+
base.send(:include, DataMapper::Resource)
|
6
|
+
base.send(:include, Sunspot::ActiveRedis)
|
7
|
+
base.send(:extend, ActiveRedisClassMethods)
|
8
|
+
base.before :save, :use_param_attribute
|
9
|
+
base.after :save, :add_to_index
|
10
|
+
base.after :destroy, :remove_from_index
|
11
|
+
base.class_eval do
|
12
|
+
alias_method :to_param, :new_param
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_to_index
|
17
|
+
if self.class.is_using_sunspot
|
18
|
+
Sunspot.index!(self)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def remove_from_index
|
23
|
+
if self.class.is_using_sunspot
|
24
|
+
Sunspot.remove!(self)
|
25
|
+
end
|
26
|
+
end
|
4
27
|
|
5
|
-
|
28
|
+
def use_param_attribute
|
29
|
+
if self.class.param_attribute != nil
|
30
|
+
self.param_name = self.send(self.class.param_attribute).parameterize
|
31
|
+
end
|
32
|
+
end
|
6
33
|
|
7
|
-
def
|
8
|
-
id.to_s
|
34
|
+
def new_param
|
35
|
+
self.class.param_attribute == nil ? id.to_s : self.param_name.to_s
|
9
36
|
end
|
10
37
|
|
11
38
|
def self.find_by_param_name(param_name)
|
@@ -41,4 +68,16 @@ class ActiveRedis
|
|
41
68
|
self.id
|
42
69
|
end
|
43
70
|
|
71
|
+
module ActiveRedisClassMethods
|
72
|
+
attr_accessor :param_attribute, :is_using_sunspot
|
73
|
+
|
74
|
+
def param_attribute_property(property)
|
75
|
+
@param_attribute = property
|
76
|
+
end
|
77
|
+
|
78
|
+
def add_sunspot_hooks
|
79
|
+
@is_using_sunspot = true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
44
83
|
end
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.2
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alex Barlow
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-04-06 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|