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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80002f51b0e8d0497984bd9868fcd9e3b52d3f1e
4
- data.tar.gz: 9bcb0d60827406630a66d18436d91c3852c65ac4
3
+ metadata.gz: 452eed9b7cf302095dda7f7c8fb1fc4d9056d486
4
+ data.tar.gz: f23c5754c966622f5055a5ce703d8bb9ff8fdc87
5
5
  SHA512:
6
- metadata.gz: 630b27e23f2be9306aac3d7e020c2559ec6e14204852b4da90dc2d33fedffc4f24e7117acc0990835d44a9f8d3914b8b01832b48002a45d1831b0bef3a3b0ef3
7
- data.tar.gz: 7268b939b048db1df7cabe598f9f5dae3030c05001c7e785ddcd9d69d306ec280498f3ed52bae73f8a9dce35ee6ce5080c146b735cb15603f04b2b05517c396f
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 = Resque::Job.const_get(class_name).find(id)
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 = Resque::Job.const_get(data.gsub(/^#{CLASS_PREFIX}/,''))
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
@@ -1,3 +1,3 @@
1
1
  module ResqueExtensions
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  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
@@ -51,6 +51,18 @@ RSpec.configure do |config|
51
51
 
52
52
  end
53
53
 
54
+ module RootModule
55
+ class InnerClass
56
+ def self.my_class_method(arg)
57
+ end
58
+ end
59
+ end
60
+
61
+ module InnerClass
62
+ def self.my_class_method(arg)
63
+ end
64
+ end
65
+
54
66
  end
55
67
 
56
68
  end
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
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-25 00:00:00.000000000 Z
11
+ date: 2013-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resque