job_boss 0.5.7 → 0.5.8

Sign up to get free protection for your applications and to get access to all the features.
data/job_boss.gemspec CHANGED
@@ -4,7 +4,7 @@ $:.unshift lib unless $:.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "job_boss"
7
- s.version = '0.5.7'
7
+ s.version = '0.5.8'
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Brian Underwood"]
10
10
  s.email = ["ml+job_boss@semi-sentient.com"]
data/lib/job_boss/job.rb CHANGED
@@ -199,21 +199,26 @@ private
199
199
  raise ArgumentError, "Invalid path (must have #)" unless path.match(/.#./)
200
200
  controller, action = path.split('#')
201
201
 
202
- controller_object = begin
203
- Kernel.const_get("#{controller.classify}Jobs").new
202
+ controller_objects = []
203
+ begin
204
+ controller_objects << Kernel.const_get("#{controller.classify}Jobs").new
204
205
  rescue NameError
205
- begin
206
- Kernel.const_get("#{controller.classify}")
207
- rescue NameError
208
- raise ArgumentError, "Invalid controller: #{controller}"
209
- end
210
206
  end
211
-
212
- raise ArgumentError, "Invalid path action: #{action}" unless controller_object.respond_to?(action)
213
-
207
+
208
+ begin
209
+ controller_objects << Kernel.const_get("#{controller.classify}")
210
+ rescue NameError
211
+ end
212
+
213
+ raise ArgumentError, "Invalid controller: #{controller}" if controller_objects.empty?
214
+
215
+ controller_object = controller_objects.detect {|controller_object| controller_object.respond_to?(action) }
216
+
217
+ raise ArgumentError, "Invalid path action: #{action}" if !controller_object
218
+
214
219
  controller_object.send(action, *args)
215
220
  end
216
-
221
+
217
222
  def pending_paths
218
223
  self.pending.except(:order).select('DISTINCT path').collect(&:path)
219
224
  end
@@ -6,10 +6,11 @@ module JobBoss
6
6
 
7
7
  method_name = method_id.id2name
8
8
 
9
- if @class && @controller
9
+ if @classes && @controller
10
10
  # In here, we've already figured out the class, so assume the method_missing call is to the method
11
+ actionable_class = @classes.detect {|controller_class| controller_class.respond_to?(method_name) }
11
12
 
12
- if @class.respond_to?(method_name)
13
+ if actionable_class
13
14
  require 'job_boss/job'
14
15
  path = "#{@controller}##{method_name}"
15
16
 
@@ -23,22 +24,21 @@ module JobBoss
23
24
  end
24
25
  else
25
26
  # Check to see if there's a class
27
+ @classes = []
26
28
  begin
27
- # If we find a class that ends in "Jobs", we instanciate it and call an instance method
28
- @class = Kernel.const_get("#{method_name.classify}Jobs").new
29
-
30
- @controller = method_name
29
+ @classes << Kernel.const_get("#{method_name.classify}Jobs").new
31
30
  rescue NameError
32
- begin
33
- # If we don't find a class that ends in "Jobs", we're going to call a class method
34
- @class = Kernel.const_get("#{method_name.classify}")
35
-
36
- @controller = method_name
37
- rescue
38
- raise ArgumentError, "Invalid controller"
39
- end
40
31
  end
41
32
 
33
+ begin
34
+ @classes << Kernel.const_get("#{method_name.classify}")
35
+ rescue
36
+ end
37
+
38
+ raise ArgumentError, "Invalid controller" if @classes.blank?
39
+
40
+ @controller = method_name
41
+
42
42
  self
43
43
  end
44
44
  end
@@ -0,0 +1,7 @@
1
+ class Sleep < ActiveRecord::Base
2
+ class << self
3
+ def add_snoozes(i,j)
4
+ i + j
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,4 @@
1
1
  require 'rubygems'
2
2
  require 'active_record'
3
3
  require File.expand_path('../../app/models/penguin', __FILE__)
4
+ require File.expand_path('../../app/models/sleep', __FILE__)
@@ -91,6 +91,16 @@ class DaemonTest < ActiveSupport::TestCase
91
91
  assert_equal "I can't not do that, Dave.", error.message
92
92
  assert_equal Array, error.backtrace.class
93
93
 
94
+
95
+
96
+ # Test calling method where there is both a Sleep model and a SleepJobs class
97
+ job = Boss.queue.sleep.add_snoozes(2, 5)
98
+
99
+ Job.wait_for_jobs(job)
100
+
101
+ assert_equal 7, job.result
102
+
103
+
94
104
  stop_daemon
95
105
  end
96
106
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 7
9
- version: 0.5.7
8
+ - 8
9
+ version: 0.5.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brian Underwood
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-12 00:00:00 -05:00
17
+ date: 2010-12-20 00:00:00 -05:00
18
18
  default_executable: job_boss
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -144,6 +144,7 @@ files:
144
144
  - test/app_root/app/jobs/sleep_jobs.rb
145
145
  - test/app_root/app/jobs/string_jobs.rb
146
146
  - test/app_root/app/models/penguin.rb
147
+ - test/app_root/app/models/sleep.rb
147
148
  - test/app_root/config/database.yml
148
149
  - test/app_root/config/environment.rb
149
150
  - test/test_helper.rb
@@ -190,6 +191,7 @@ test_files:
190
191
  - test/app_root/app/jobs/sleep_jobs.rb
191
192
  - test/app_root/app/jobs/string_jobs.rb
192
193
  - test/app_root/app/models/penguin.rb
194
+ - test/app_root/app/models/sleep.rb
193
195
  - test/app_root/config/database.yml
194
196
  - test/app_root/config/environment.rb
195
197
  - test/test_helper.rb