resque_extensions 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/resque_extensions/async_method.rb +14 -2
- data/lib/resque_extensions/version.rb +1 -1
- data/spec/lib/resque_extensions/async_method_spec.rb +23 -12
- data/spec/spec_helper.rb +12 -0
- 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: 452eed9b7cf302095dda7f7c8fb1fc4d9056d486
|
4
|
+
data.tar.gz: f23c5754c966622f5055a5ce703d8bb9ff8fdc87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce440e2e0fca8e28ed7f3d7c699f0902d853b85b20a4b97c1330ca6a1657438608100ec6b67d832cdae68a287fcd33abe67cfcefb3ad6bb4f4410fd4c951fe28
|
7
|
+
data.tar.gz: 44395467176955c6b894566d2c9a40fa306a48e2956ef229f9465f15935504e8a8ee496c715c5f57116408c9ff285280320954ddea2ab22c41e1b8c7acddcc50
|
@@ -73,10 +73,10 @@ module ResqueExtensions
|
|
73
73
|
data = data.split("::")
|
74
74
|
id = data.pop
|
75
75
|
class_name = data[1..-1].join("::")
|
76
|
-
data =
|
76
|
+
data = self.constantize(class_name).find(id)
|
77
77
|
# classes become strings prefixed by _Class
|
78
78
|
elsif data.to_s =~ /^#{CLASS_PREFIX}/
|
79
|
-
data =
|
79
|
+
data = self.constantize(data.gsub(/^#{CLASS_PREFIX}/, ''))
|
80
80
|
end
|
81
81
|
# return data
|
82
82
|
data
|
@@ -124,5 +124,17 @@ module ResqueExtensions
|
|
124
124
|
# if we have overlaps, we've been passed options
|
125
125
|
return (keys & OPTIONAL_SETTINGS).length > 0
|
126
126
|
end
|
127
|
+
|
128
|
+
def self.constantize(namespaced_class)
|
129
|
+
names = namespaced_class.split('::')
|
130
|
+
names.shift if names.empty? || names.first.empty?
|
131
|
+
|
132
|
+
constant = Object
|
133
|
+
names.each do |name|
|
134
|
+
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
135
|
+
end
|
136
|
+
|
137
|
+
constant
|
138
|
+
end
|
127
139
|
end
|
128
140
|
end
|
@@ -15,7 +15,6 @@ module ResqueExtensions
|
|
15
15
|
|
16
16
|
job = Resque.reserve("default")
|
17
17
|
job.perform
|
18
|
-
|
19
18
|
end
|
20
19
|
|
21
20
|
it "deserializes and calls a method on an ActiveRecord" do
|
@@ -33,6 +32,18 @@ module ResqueExtensions
|
|
33
32
|
|
34
33
|
end
|
35
34
|
|
35
|
+
it 'properly looks up class names that are namespaced' do
|
36
|
+
|
37
|
+
async_method = AsyncMethod.new(RootModule::InnerClass, :my_class_method, 'a')
|
38
|
+
async_method.enqueue!
|
39
|
+
|
40
|
+
RootModule::InnerClass.expects(:send).with('my_class_method', 'a')
|
41
|
+
InnerClass.expects(:send).never
|
42
|
+
|
43
|
+
job = Resque.reserve('default')
|
44
|
+
job.perform
|
45
|
+
end
|
46
|
+
|
36
47
|
end
|
37
48
|
|
38
49
|
|
@@ -81,9 +92,9 @@ module ResqueExtensions
|
|
81
92
|
async_method.enqueue!
|
82
93
|
|
83
94
|
job = Resque.reserve("default")
|
84
|
-
|
95
|
+
|
85
96
|
job.payload.should eql({
|
86
|
-
"class" => "ResqueExtensions::AsyncMethod",
|
97
|
+
"class" => "ResqueExtensions::AsyncMethod",
|
87
98
|
"args" => ["_Class::MyClass", "my_class_method"]
|
88
99
|
})
|
89
100
|
|
@@ -97,11 +108,11 @@ module ResqueExtensions
|
|
97
108
|
async_method.enqueue!
|
98
109
|
|
99
110
|
job = Resque.reserve("default")
|
100
|
-
|
111
|
+
|
101
112
|
job.payload.should eql({
|
102
|
-
"class" => "ResqueExtensions::AsyncMethod",
|
113
|
+
"class" => "ResqueExtensions::AsyncMethod",
|
103
114
|
"args" => [
|
104
|
-
"_ActiveRecord::MyClass::#{my_instance.id}",
|
115
|
+
"_ActiveRecord::MyClass::#{my_instance.id}",
|
105
116
|
"my_instance_method"
|
106
117
|
]
|
107
118
|
})
|
@@ -113,10 +124,10 @@ module ResqueExtensions
|
|
113
124
|
my_instance = MyClass.create(:name => "Dan")
|
114
125
|
|
115
126
|
async_method = AsyncMethod.new(
|
116
|
-
MyClass,
|
117
|
-
:my_class_method,
|
118
|
-
[my_instance],
|
119
|
-
my_instance,
|
127
|
+
MyClass,
|
128
|
+
:my_class_method,
|
129
|
+
[my_instance],
|
130
|
+
my_instance,
|
120
131
|
{:a => my_instance}
|
121
132
|
)
|
122
133
|
async_method.enqueue!
|
@@ -127,9 +138,9 @@ module ResqueExtensions
|
|
127
138
|
job = Resque.reserve("default")
|
128
139
|
|
129
140
|
job.payload.should eql({
|
130
|
-
"class" => "ResqueExtensions::AsyncMethod",
|
141
|
+
"class" => "ResqueExtensions::AsyncMethod",
|
131
142
|
"args" => [
|
132
|
-
"_Class::MyClass",
|
143
|
+
"_Class::MyClass",
|
133
144
|
"my_class_method",
|
134
145
|
[instance_string],
|
135
146
|
instance_string,
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Langevin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: resque
|