wireframe-backgrounded 0.2.0 → 0.3.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/README.rdoc CHANGED
@@ -15,13 +15,6 @@ Simple API for running model methods in the background
15
15
  #usage
16
16
  user = User.new
17
17
  user.do_stuff_backgrounded
18
-
19
- = Configuration
20
-
21
- Packaged with Delayed Job handler out of the box, but can support any custom handler to perform background work.
22
-
23
- # rails config/environment.rb
24
- Backgrounded.handler = DelayedJobHandler.new
25
18
 
26
19
  = Installation
27
20
 
@@ -33,6 +26,17 @@ Rails environment.rb configuration
33
26
 
34
27
  config.gem 'wireframe-backgrounded', :source => 'http://gems.github.com', :lib => 'backgrounded'
35
28
 
29
+ = Configuration
30
+
31
+ Packaged with both Delayed Job and JobFu handler out of the box, but can support any custom handler to perform background work.
32
+
33
+ # rails config/initializers/backgrounded.rb
34
+
35
+ # Delayed Job, see http://github.com/tobi/delayed_job/tree/master
36
+ Backgrounded.handler = Backgrounded::Handler::DelayedJobHandler.new
37
+
38
+ # Job Fu, see http://github.com/jnstq/job_fu/tree
39
+ Backgrounded.handler = Backgrounded::Handler::JobFuHandler.new
36
40
 
37
41
  == Copyright
38
42
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 2
3
+ :minor: 3
4
4
  :patch: 0
data/backgrounded.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{backgrounded}
5
- s.version = "0.2.0"
5
+ s.version = "0.3.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ryan Sonnek"]
9
- s.date = %q{2009-07-21}
9
+ s.date = %q{2009-08-11}
10
10
  s.email = %q{ryan.sonnek@gmail.com}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
@@ -21,6 +21,10 @@ Gem::Specification.new do |s|
21
21
  "VERSION.yml",
22
22
  "backgrounded.gemspec",
23
23
  "lib/backgrounded.rb",
24
+ "lib/handler.rb",
25
+ "lib/handler/delayed_job_handler.rb",
26
+ "lib/handler/inprocess_handler.rb",
27
+ "lib/handler/job_fu_handler.rb",
24
28
  "test/backgrounded_test.rb",
25
29
  "test/test_helper.rb"
26
30
  ]
data/lib/backgrounded.rb CHANGED
@@ -5,25 +5,9 @@ module Backgrounded
5
5
  def self.handler
6
6
  @@handler ||= Backgrounded::Handler::InprocessHandler.new
7
7
  end
8
- module Handler
9
- #simple handler to process synchronously and not actually in the background
10
- #useful for testing
11
- class InprocessHandler
12
- def request(object, method)
13
- object.send method
14
- end
15
- end
16
-
17
- # invoke the operation in the background using delayed job
18
- # see http://github.com/tobi/delayed_job/tree/master
19
- class DelayedJobHandler
20
- require 'delayed_job'
21
- def request(object, method)
22
- object.send_later(method.to_sym)
23
- end
24
- end
25
- end
26
-
8
+
9
+ autoload :Handler, 'handler'
10
+
27
11
  module Model
28
12
  def self.included(base)
29
13
  base.extend(ClassMethods)
@@ -32,8 +16,9 @@ module Backgrounded
32
16
  module ClassMethods
33
17
  def backgrounded(*methods)
34
18
  methods.each do |method|
35
- define_method "#{method.to_s}_backgrounded" do
36
- Backgrounded.handler.request(self, method)
19
+ method_basename, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
20
+ define_method :"#{method_basename}_backgrounded#{punctuation}" do |*args|
21
+ Backgrounded.handler.request(self, method, *args)
37
22
  end
38
23
  end
39
24
  include Backgrounded::Model::InstanceMethods
@@ -43,7 +28,7 @@ module Backgrounded
43
28
 
44
29
  module SingletonMethods
45
30
  end
46
-
31
+
47
32
  module InstanceMethods
48
33
  end
49
34
  end
data/lib/handler.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'activesupport'
2
+
3
+ module Backgrounded
4
+ module Handler
5
+ Dir["#{File.dirname(__FILE__)}/#{name.demodulize.underscore}/*.rb"].each do |handler_file|
6
+ handler_name = File.basename(handler_file, '.rb').camelize.to_sym
7
+ autoload handler_name, File.expand_path(handler_file)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ require 'delayed_job'
2
+
3
+ module Backgrounded
4
+ module Handler
5
+ # invoke the operation in the background using delayed job
6
+ # see http://github.com/tobi/delayed_job/tree/master
7
+ class DelayedJobHandler
8
+ def request(object, method, *args)
9
+ object.send_later(method.to_sym, *args)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Backgrounded
2
+ module Handler
3
+ #simple handler to process synchronously and not actually in the background
4
+ #useful for testing
5
+ class InprocessHandler
6
+ def request(object, method, *args)
7
+ object.send method, *args
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ require 'job_fu'
2
+
3
+ module Backgrounded
4
+ module Handler
5
+ # invoke the operation in the background using job fu
6
+ # see http://github.com/jnstq/job_fu/tree
7
+ class JobFuHandler
8
+ # ==== Parameters
9
+ # Optional argment hash will be picked up by the request method
10
+ #
11
+ # * <tt>:priority</tt> - priority for the job
12
+ # * <tt>:at</tt> - when the job should run
13
+ #
14
+ def request(object, method, *args)
15
+ opt = args.extract_options!
16
+ priority, process_at = opt[:priority], opt[:at]
17
+ JobFu::Job.enqueue JobFu::ProcessableMethod.new(object, method, *args), priority, process_at
18
+ end
19
+ end
20
+ end
21
+ end
@@ -23,6 +23,13 @@ class Post
23
23
  end
24
24
  end
25
25
 
26
+ class Comment
27
+ backgrounded :delete_spam!
28
+
29
+ def delete_spam!
30
+ end
31
+ end
32
+
26
33
  class BackgroundedTest < Test::Unit::TestCase
27
34
  context 'an object with a single backgrounded method' do
28
35
  setup do
@@ -38,10 +45,18 @@ class BackgroundedTest < Test::Unit::TestCase
38
45
  setup do
39
46
  @person = Person.new
40
47
  end
41
- should 'raise error if passing method parameters' do
42
- assert_raises ArgumentError, "method parameters are not currently supported for backgrounded methods." do
43
- @person.do_stuff_backgrounded('ryan', 2, 3)
44
- end
48
+ should 'forward them' do
49
+ @person.expects(:do_stuff).with('ryan', 2, 3)
50
+ @person.do_stuff_backgrounded('ryan', 2, 3)
51
+ end
52
+ end
53
+
54
+ context 'an object with a backgrounded method included punctuation' do
55
+ setup do
56
+ @comment = Comment.new
57
+ end
58
+ should 'move punctuation to the end of the new method' do
59
+ assert @comment.respond_to?(:'delete_spam_backgrounded!')
45
60
  end
46
61
  end
47
62
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wireframe-backgrounded
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Sonnek
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-21 00:00:00 -07:00
12
+ date: 2009-08-11 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -31,10 +31,15 @@ files:
31
31
  - VERSION.yml
32
32
  - backgrounded.gemspec
33
33
  - lib/backgrounded.rb
34
+ - lib/handler.rb
35
+ - lib/handler/delayed_job_handler.rb
36
+ - lib/handler/inprocess_handler.rb
37
+ - lib/handler/job_fu_handler.rb
34
38
  - test/backgrounded_test.rb
35
39
  - test/test_helper.rb
36
40
  has_rdoc: true
37
41
  homepage: http://github.com/wireframe/backgrounded
42
+ licenses:
38
43
  post_install_message:
39
44
  rdoc_options:
40
45
  - --charset=UTF-8
@@ -55,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
60
  requirements: []
56
61
 
57
62
  rubyforge_project:
58
- rubygems_version: 1.2.0
63
+ rubygems_version: 1.3.5
59
64
  signing_key:
60
65
  specification_version: 2
61
66
  summary: Simple API to run Model methods in the background