resque-methodize 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +32 -0
  3. data/Rakefile +25 -0
  4. data/lib/resque/plugins/methodize.rb +22 -0
  5. metadata +86 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Ken Robertson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ Software), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ Resque Methodize
2
+ =================
3
+
4
+ Extends Resque to allow you to call individual methods on a job class. This allows you to group common jobs in a single class rather than having multiple classes that differ slightly or more complex logic to handle variations within a single job.
5
+
6
+ For example:
7
+
8
+ require 'resque/plugins/methodize'
9
+
10
+ class MyJob
11
+ extend Resque::Plugins::Priority
12
+ @queue = :jobs
13
+
14
+ def sample1
15
+ puts "Doing stuff"
16
+ end
17
+
18
+ def sample2(message)
19
+ puts "Doing other stuff while #{message}"
20
+ end
21
+ end
22
+
23
+ # Enqueue the job
24
+ MyJob.enqueue_sample1
25
+ MyJob.enqueue_sample2('taking out the garbage')
26
+
27
+ This allows a shorter notation for triggering jobs though "enqueue_*method*" and calling of a specific instance method within the job.
28
+
29
+ Inspiration
30
+ -----------
31
+
32
+ This plugin was inspired by the task framework cooked up at [Involver](http://involver.com) by [Mike Wadhera](http://github.com/mikewadhera). The task framework, known as Queueable, is built on top of JMS and runs on JRuby. It follows the same process of tasks being instance methods and similar notation for enqueuing. I personally use Resque and wanted to bring that kind of notation and style to my usage of Resque.
@@ -0,0 +1,25 @@
1
+ desc "Push a new version to Gemcutter"
2
+ task :publish do
3
+ VERSION = File.read('VERSION').chomp
4
+
5
+ sh "gem build resque-methodize.gemspec"
6
+ sh "gem push resque-methodize-#{VERSION}.gem"
7
+ sh "git tag v#{VERSION}"
8
+ sh "git push origin v#{VERSION}"
9
+ sh "git push origin master"
10
+ sh "git clean -fd"
11
+ end
12
+
13
+ begin
14
+ require 'spec/rake/spectask'
15
+
16
+ desc "Run all specs"
17
+ Spec::Rake::SpecTask.new('spec') do |t|
18
+ t.rcov = false
19
+ t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/,features\/,rake\/,Gemfile,yaml,eval,FORWARDABLE,DELEGATE,jar --aggregate coverage.data}
20
+ t.rcov_opts << %[-o "coverage"]
21
+ t.spec_files = FileList['spec/**/*_spec.rb']
22
+ end
23
+ rescue LoadError
24
+ puts "RSpec (or a dependency) not available. Install it with: gem install rspec -v 1.3.1"
25
+ end
@@ -0,0 +1,22 @@
1
+ module Resque
2
+ module Plugins
3
+ module Methodize
4
+
5
+ # Generic perform that calls to the specified method
6
+ def perform(method, *args)
7
+ self.new.send(method.to_sym, *args)
8
+ end
9
+
10
+ # Dynamic API for enqueuing jobs
11
+ def method_missing(m, *args)
12
+ super unless m.to_s =~ /^enqueue_/
13
+
14
+ # Enqueue the specified method
15
+ method = m.to_s.sub(/^enqueue_/, '')
16
+ queue = self.instance_variable_get(:@queue) || (self.respond_to?(:queue) and self.queue)
17
+ Resque::Job.create(queue, self, method, *args)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque-methodize
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 1
10
+ version: 1.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Ken Robertson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-01 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: resque
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 31
30
+ segments:
31
+ - 0
32
+ - 0
33
+ - 0
34
+ version: 0.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: " Resque-Methodize is a plugin for the Resque job library that allows\n easy triggering of individual methods on a job class.\n"
38
+ email: ken@invalidlogic.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.md
46
+ files:
47
+ - README.md
48
+ - Rakefile
49
+ - LICENSE
50
+ - lib/resque/plugins/methodize.rb
51
+ has_rdoc: true
52
+ homepage: http://github.com/krobertson/resque-methodize
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options:
57
+ - --charset=UTF-8
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.4.2
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: A Resque plugin that allows you to call individual methods on a Resque job
85
+ test_files: []
86
+