wireframe-backgrounded 0.2.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/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +39 -0
- data/Rakefile +56 -0
- data/VERSION.yml +4 -0
- data/backgrounded.gemspec +47 -0
- data/lib/backgrounded.rb +52 -0
- data/test/backgrounded_test.rb +60 -0
- data/test/test_helper.rb +11 -0
- metadata +64 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Ryan Sonnek
|
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.
|
data/README.rdoc
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
= backgrounded
|
2
|
+
|
3
|
+
Simple API for running model methods in the background
|
4
|
+
|
5
|
+
= Usage
|
6
|
+
|
7
|
+
#declaration
|
8
|
+
class User
|
9
|
+
backgrounded :do_stuff
|
10
|
+
def do_stuff
|
11
|
+
# do all your work here
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
#usage
|
16
|
+
user = User.new
|
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
|
+
|
26
|
+
= Installation
|
27
|
+
|
28
|
+
Command line installation
|
29
|
+
|
30
|
+
sudo gem install wireframe-backgrounded
|
31
|
+
|
32
|
+
Rails environment.rb configuration
|
33
|
+
|
34
|
+
config.gem 'wireframe-backgrounded', :source => 'http://gems.github.com', :lib => 'backgrounded'
|
35
|
+
|
36
|
+
|
37
|
+
== Copyright
|
38
|
+
|
39
|
+
Copyright (c) 2009 Ryan Sonnek. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "backgrounded"
|
8
|
+
gem.summary = %Q{Simple API to run Model methods in the background}
|
9
|
+
gem.email = "ryan.sonnek@gmail.com"
|
10
|
+
gem.homepage = "http://github.com/wireframe/backgrounded"
|
11
|
+
gem.authors = ["Ryan Sonnek"]
|
12
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
|
+
end
|
14
|
+
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
21
|
+
test.libs << 'lib' << 'test'
|
22
|
+
test.pattern = 'test/**/*_test.rb'
|
23
|
+
test.verbose = true
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rcov/rcovtask'
|
28
|
+
Rcov::RcovTask.new do |test|
|
29
|
+
test.libs << 'test'
|
30
|
+
test.pattern = 'test/**/*_test.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
task :rcov do
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => :test
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
if File.exist?('VERSION.yml')
|
45
|
+
config = YAML.load(File.read('VERSION.yml'))
|
46
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
47
|
+
else
|
48
|
+
version = ""
|
49
|
+
end
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "backgrounded #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
56
|
+
|
data/VERSION.yml
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{backgrounded}
|
5
|
+
s.version = "0.2.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Ryan Sonnek"]
|
9
|
+
s.date = %q{2009-07-21}
|
10
|
+
s.email = %q{ryan.sonnek@gmail.com}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".document",
|
17
|
+
".gitignore",
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION.yml",
|
22
|
+
"backgrounded.gemspec",
|
23
|
+
"lib/backgrounded.rb",
|
24
|
+
"test/backgrounded_test.rb",
|
25
|
+
"test/test_helper.rb"
|
26
|
+
]
|
27
|
+
s.has_rdoc = true
|
28
|
+
s.homepage = %q{http://github.com/wireframe/backgrounded}
|
29
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
30
|
+
s.require_paths = ["lib"]
|
31
|
+
s.rubygems_version = %q{1.3.1}
|
32
|
+
s.summary = %q{Simple API to run Model methods in the background}
|
33
|
+
s.test_files = [
|
34
|
+
"test/backgrounded_test.rb",
|
35
|
+
"test/test_helper.rb"
|
36
|
+
]
|
37
|
+
|
38
|
+
if s.respond_to? :specification_version then
|
39
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
40
|
+
s.specification_version = 2
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
43
|
+
else
|
44
|
+
end
|
45
|
+
else
|
46
|
+
end
|
47
|
+
end
|
data/lib/backgrounded.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'activesupport'
|
2
|
+
|
3
|
+
module Backgrounded
|
4
|
+
mattr_accessor :handler
|
5
|
+
def self.handler
|
6
|
+
@@handler ||= Backgrounded::Handler::InprocessHandler.new
|
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
|
+
|
27
|
+
module Model
|
28
|
+
def self.included(base)
|
29
|
+
base.extend(ClassMethods)
|
30
|
+
end
|
31
|
+
|
32
|
+
module ClassMethods
|
33
|
+
def backgrounded(*methods)
|
34
|
+
methods.each do |method|
|
35
|
+
define_method "#{method.to_s}_backgrounded" do
|
36
|
+
Backgrounded.handler.request(self, method)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
include Backgrounded::Model::InstanceMethods
|
40
|
+
extend Backgrounded::Model::SingletonMethods
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module SingletonMethods
|
45
|
+
end
|
46
|
+
|
47
|
+
module InstanceMethods
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
Object.send(:include, Backgrounded::Model)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class User
|
4
|
+
backgrounded :do_stuff
|
5
|
+
|
6
|
+
def do_stuff
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Person
|
11
|
+
backgrounded :do_stuff
|
12
|
+
|
13
|
+
def do_stuff(name, place, location)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Post
|
18
|
+
backgrounded :do_stuff, :notify_users
|
19
|
+
|
20
|
+
def do_stuff
|
21
|
+
end
|
22
|
+
def notify_users
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class BackgroundedTest < Test::Unit::TestCase
|
27
|
+
context 'an object with a single backgrounded method' do
|
28
|
+
setup do
|
29
|
+
@user = User.new
|
30
|
+
end
|
31
|
+
should "execute method in background" do
|
32
|
+
@user.expects(:do_stuff)
|
33
|
+
@user.do_stuff_backgrounded
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'an object with a backgrounded method that accepts parameters' do
|
38
|
+
setup do
|
39
|
+
@person = Person.new
|
40
|
+
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
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'an object with multiple backgrounded methods' do
|
49
|
+
setup do
|
50
|
+
@post = Post.new
|
51
|
+
end
|
52
|
+
should "execute method either method in background" do
|
53
|
+
@post.expects(:do_stuff)
|
54
|
+
@post.do_stuff_backgrounded
|
55
|
+
|
56
|
+
@post.expects(:notify_users)
|
57
|
+
@post.notify_users_backgrounded
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wireframe-backgrounded
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Sonnek
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-21 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: ryan.sonnek@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- .document
|
27
|
+
- .gitignore
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
- Rakefile
|
31
|
+
- VERSION.yml
|
32
|
+
- backgrounded.gemspec
|
33
|
+
- lib/backgrounded.rb
|
34
|
+
- test/backgrounded_test.rb
|
35
|
+
- test/test_helper.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://github.com/wireframe/backgrounded
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --charset=UTF-8
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.2.0
|
59
|
+
signing_key:
|
60
|
+
specification_version: 2
|
61
|
+
summary: Simple API to run Model methods in the background
|
62
|
+
test_files:
|
63
|
+
- test/backgrounded_test.rb
|
64
|
+
- test/test_helper.rb
|