commonthread-rails 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/commonthread-rails.gemspec +3 -2
- data/lib/commonthread-rails.rb +4 -0
- data/lib/commonthread/monkey_patches.rb +0 -16
- data/lib/resque/mixin/async.rb +55 -0
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
data/commonthread-rails.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{commonthread-rails}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["CommonThread"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-02-04}
|
13
13
|
s.description = %q{commonthread-rails is a collection of things that make rails development better for us. It includes date formats, monkey patches to String, Array and NilClass to make things nicer. An Encrypter using blowfish. Also, some rails filters}
|
14
14
|
s.email = %q{hello@commonthread.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
"lib/commonthread/filters.rb",
|
31
31
|
"lib/commonthread/lipsum.rb",
|
32
32
|
"lib/commonthread/monkey_patches.rb",
|
33
|
+
"lib/resque/mixin/async.rb",
|
33
34
|
"test/helper.rb",
|
34
35
|
"test/test_monkey_patches.rb"
|
35
36
|
]
|
data/lib/commonthread-rails.rb
CHANGED
@@ -151,21 +151,5 @@ if defined?(ActiveRecord)
|
|
151
151
|
prefix ||= 'new' if self.new_record?
|
152
152
|
[ prefix, self.class.name, self.id ].compact.join('_').downcase
|
153
153
|
end
|
154
|
-
|
155
|
-
if defined?(Resque)
|
156
|
-
def self.queue
|
157
|
-
@queue || 'default'
|
158
|
-
end
|
159
|
-
|
160
|
-
# This will be called by a worker when a job needs to be processed
|
161
|
-
def self.perform(id, method, *args)
|
162
|
-
find(id).send(method, *args)
|
163
|
-
end
|
164
|
-
|
165
|
-
# We can pass this any Repository instance method that we want to run later.
|
166
|
-
def async(method, *args)
|
167
|
-
Resque.enqueue(self.class, self.id, method, *args)
|
168
|
-
end
|
169
|
-
end
|
170
154
|
end
|
171
155
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Resque
|
2
|
+
module Mixin
|
3
|
+
# Module that provides easy queueing of jobs.
|
4
|
+
# Transparently handles instance and class methods.
|
5
|
+
#
|
6
|
+
# If you consider this class:
|
7
|
+
#
|
8
|
+
# class Repository < ActiveRecord::Base
|
9
|
+
# include Resque::Mixin::Async
|
10
|
+
# @queue = :high_priority
|
11
|
+
#
|
12
|
+
# def self.create_index
|
13
|
+
# # code
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# def notify_watchers
|
17
|
+
# # code
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# you can queue new jobs on both the class and an instance like this:
|
22
|
+
#
|
23
|
+
# @repository.async(:notify_watchers)
|
24
|
+
# Repository.async(:create_index)
|
25
|
+
#
|
26
|
+
module Async
|
27
|
+
def self.included(base)
|
28
|
+
base.extend(ClassMethods)
|
29
|
+
end
|
30
|
+
|
31
|
+
def async(method, *args)
|
32
|
+
Resque.enqueue(self.class, id, method, *args)
|
33
|
+
end
|
34
|
+
|
35
|
+
module ClassMethods
|
36
|
+
def queue
|
37
|
+
@queue || 'default'
|
38
|
+
end
|
39
|
+
|
40
|
+
def async(method, *args)
|
41
|
+
Resque.enqueue(self, nil, method, *args)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Performs a class method if id is nil or
|
45
|
+
# an instance method if id has a value.
|
46
|
+
def perform(*args)
|
47
|
+
id, method = args.shift(2)
|
48
|
+
|
49
|
+
obj = id ? find(id) : self
|
50
|
+
obj.send(method, *args)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commonthread-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CommonThread
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-02-04 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- lib/commonthread/filters.rb
|
56
56
|
- lib/commonthread/lipsum.rb
|
57
57
|
- lib/commonthread/monkey_patches.rb
|
58
|
+
- lib/resque/mixin/async.rb
|
58
59
|
- test/helper.rb
|
59
60
|
- test/test_monkey_patches.rb
|
60
61
|
has_rdoc: true
|