active_job-performs 0.1.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +31 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +50 -10
- data/README.md +46 -0
- data/lib/active_job/performs/version.rb +1 -1
- data/lib/active_job/performs.rb +15 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5741d785f1439dac15d6ec2734d40e5560013f69025977713771309c7f15c4c7
|
4
|
+
data.tar.gz: c01e5d7ebe8f599024cd5eba79011a959d2e31c8d5141b787b46d55b1150b73b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ea09dcf8da5a0c7c1f5181ed70e07c3a3028d7d12c5c84cece6c6d59ab6a7921ea7ddc05180fd2b8f551332277a2e032bee0c057398a33b4e7f3a645f451c3f
|
7
|
+
data.tar.gz: 32899d17334f35819a1aa61ffa56c58a492d1b304a003b1e5d6156a26450087e2ac7083021a312269d2c2ee0519e43ad78d129629c6641036f5ad222130f6c3a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,36 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.0] - 2023-01-12
|
4
|
+
|
5
|
+
- Supports `private performs :some_method`
|
6
|
+
|
7
|
+
Which then generates a private `some_method_later` method.
|
8
|
+
|
9
|
+
This was already technically supported but a test was added to declare it expected.
|
10
|
+
|
11
|
+
- Support method suffixes ! and ?
|
12
|
+
|
13
|
+
You can call `performs :some_method!` and have `some_method_later!` generated. Same for `?`.
|
14
|
+
|
15
|
+
- Support `performs` on private methods
|
16
|
+
|
17
|
+
Method jobs will now call methods with `send`, in case you only want to expose the generated later method to the outside world.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
class Post < ActiveRecord::Base
|
21
|
+
performs :something_low_level
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# We don't want other objects to call this, they should always use the generated later method.
|
26
|
+
def something_low_level
|
27
|
+
# …
|
28
|
+
end
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
Here, the generated `Post#something_low_level_later` is public and available but can still call into the immediate version of `something_low_level`.
|
33
|
+
|
3
34
|
## [0.1.1] - 2022-09-27
|
4
35
|
|
5
36
|
- Fixed: extend ActiveRecord::Base with ActiveJob::Performs as the README says.
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,42 +1,82 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active_job-performs (0.
|
4
|
+
active_job-performs (0.3.0)
|
5
5
|
activejob (>= 6.1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activejob (7.
|
11
|
-
activesupport (= 7.
|
10
|
+
activejob (7.1.1)
|
11
|
+
activesupport (= 7.1.1)
|
12
12
|
globalid (>= 0.3.6)
|
13
|
-
|
13
|
+
activemodel (7.1.1)
|
14
|
+
activesupport (= 7.1.1)
|
15
|
+
activerecord (7.1.1)
|
16
|
+
activemodel (= 7.1.1)
|
17
|
+
activesupport (= 7.1.1)
|
18
|
+
timeout (>= 0.4.0)
|
19
|
+
activesupport (7.1.1)
|
20
|
+
base64
|
21
|
+
bigdecimal
|
14
22
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
23
|
+
connection_pool (>= 2.2.5)
|
24
|
+
drb
|
15
25
|
i18n (>= 1.6, < 2)
|
16
26
|
minitest (>= 5.1)
|
27
|
+
mutex_m
|
17
28
|
tzinfo (~> 2.0)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
29
|
+
base64 (0.1.1)
|
30
|
+
bigdecimal (3.1.4)
|
31
|
+
concurrent-ruby (1.2.2)
|
32
|
+
connection_pool (2.4.1)
|
33
|
+
debug (1.8.0)
|
34
|
+
irb (>= 1.5.0)
|
35
|
+
reline (>= 0.3.1)
|
36
|
+
drb (2.1.1)
|
37
|
+
ruby2_keywords
|
38
|
+
globalid (1.2.1)
|
39
|
+
activesupport (>= 6.1)
|
40
|
+
i18n (1.14.1)
|
22
41
|
concurrent-ruby (~> 1.0)
|
42
|
+
io-console (0.6.0)
|
43
|
+
irb (1.8.0)
|
44
|
+
rdoc (~> 6.5)
|
45
|
+
reline (>= 0.3.6)
|
23
46
|
minitest (5.16.3)
|
24
47
|
minitest-sprint (1.2.2)
|
25
48
|
path_expander (~> 1.1)
|
49
|
+
mutex_m (0.1.2)
|
26
50
|
path_expander (1.1.1)
|
51
|
+
psych (5.1.0)
|
52
|
+
stringio
|
27
53
|
rake (13.0.6)
|
28
|
-
|
54
|
+
rdoc (6.5.0)
|
55
|
+
psych (>= 4.0.0)
|
56
|
+
reline (0.3.8)
|
57
|
+
io-console (~> 0.5)
|
58
|
+
ruby2_keywords (0.0.5)
|
59
|
+
sqlite3 (1.6.4-arm64-darwin)
|
60
|
+
sqlite3 (1.6.4-x86_64-linux)
|
61
|
+
stringio (3.0.8)
|
62
|
+
timeout (0.4.0)
|
63
|
+
tzinfo (2.0.6)
|
29
64
|
concurrent-ruby (~> 1.0)
|
30
65
|
|
31
66
|
PLATFORMS
|
32
67
|
arm64-darwin-20
|
68
|
+
arm64-darwin-22
|
33
69
|
x86_64-linux
|
34
70
|
|
35
71
|
DEPENDENCIES
|
36
72
|
active_job-performs!
|
73
|
+
activejob (>= 7.1)
|
74
|
+
activerecord (>= 7.1)
|
75
|
+
debug
|
37
76
|
minitest (~> 5.0)
|
38
77
|
minitest-sprint
|
39
78
|
rake (~> 13.0)
|
79
|
+
sqlite3
|
40
80
|
|
41
81
|
BUNDLED WITH
|
42
|
-
2.
|
82
|
+
2.4.19
|
data/README.md
CHANGED
@@ -42,6 +42,14 @@ class Post < ActiveRecord::Base
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
# On Rails 7.1, where `ActiveJob.perform_all_later` exists, we also generate
|
46
|
+
# a bulk method to enqueue many jobs at once. So you can do this:
|
47
|
+
#
|
48
|
+
# Post.unpublished.in_batches.each(&:publish_later_bulk)
|
49
|
+
def self.publish_later_bulk
|
50
|
+
ActiveJob.perform_all_later all.map { PublishJob.new(_1) }
|
51
|
+
end
|
52
|
+
|
45
53
|
# We generate `publish_later` to wrap the job execution.
|
46
54
|
def publish_later(*arguments, **options)
|
47
55
|
PublishJob.perform_later(self, *arguments, **options)
|
@@ -91,6 +99,44 @@ class Post < ActiveRecord::Base
|
|
91
99
|
end
|
92
100
|
```
|
93
101
|
|
102
|
+
#### Method suffixes
|
103
|
+
|
104
|
+
`ActiveJob::Performs` supports Ruby's stylistic method suffixes, i.e. ? and ! respectively.
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
class Post < ActiveRecord::Base
|
108
|
+
performs :publish! # Generates `publish_later!` which calls `publish!`.
|
109
|
+
performs :retract? # Generates `retract_later?` which calls `retract?`.
|
110
|
+
|
111
|
+
def publish!
|
112
|
+
…
|
113
|
+
end
|
114
|
+
|
115
|
+
def retract?
|
116
|
+
…
|
117
|
+
end
|
118
|
+
end
|
119
|
+
```
|
120
|
+
|
121
|
+
#### Private methods
|
122
|
+
|
123
|
+
`ActiveJob::Performs` also works with private methods in case you only want to expose the generated `_later` method.
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
class Post < ActiveRecord::Base
|
127
|
+
performs :publish # Generates the public `publish_later` instance method.
|
128
|
+
|
129
|
+
# Private implementation, only call `publish_later` please!
|
130
|
+
private def publish
|
131
|
+
…
|
132
|
+
end
|
133
|
+
end
|
134
|
+
```
|
135
|
+
|
136
|
+
Additionally, in case the job is meant to be internal to the object, `performs :some_method` returns `:some_method_later` which you can pass to `private`.
|
137
|
+
|
138
|
+
E.g. `private performs :some_method` will generate a private `some_method_later` method.
|
139
|
+
|
94
140
|
### Usage with ActiveRecord::AssociatedObject
|
95
141
|
|
96
142
|
The [`ActiveRecord::AssociatedObject`](https://github.com/kaspth/active_record-associated_object) gem also implements `GlobalID::Identification`, so you can do this too:
|
data/lib/active_job/performs.rb
CHANGED
@@ -34,20 +34,33 @@ module ActiveJob::Performs
|
|
34
34
|
if method.nil?
|
35
35
|
apply_performs_to(@job, **configs, &block)
|
36
36
|
else
|
37
|
+
method = method.to_s.dup
|
38
|
+
suffix = $1 if method.gsub!(/([!?])$/, "")
|
39
|
+
|
37
40
|
job = safe_define("#{method}_job".classify) { @job }
|
38
41
|
apply_performs_to(job, **configs, &block)
|
39
42
|
|
40
43
|
job.class_eval <<~RUBY, __FILE__, __LINE__ + 1 unless job.instance_method(:perform).owner == job
|
41
44
|
def perform(object, *arguments, **options)
|
42
|
-
object
|
45
|
+
object.send(:#{method}#{suffix}, *arguments, **options)
|
43
46
|
end
|
44
47
|
RUBY
|
45
48
|
|
49
|
+
if ActiveJob.respond_to?(:perform_all_later) && respond_to?(:all)
|
50
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
51
|
+
def self.#{method}_later_bulk#{suffix}
|
52
|
+
ActiveJob.perform_all_later all.map { #{job}.scoped_by_wait(_1).new(_1) }
|
53
|
+
end
|
54
|
+
RUBY
|
55
|
+
end
|
56
|
+
|
46
57
|
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
47
|
-
def #{method}_later(*arguments, **options)
|
58
|
+
def #{method}_later#{suffix}(*arguments, **options)
|
48
59
|
#{job}.scoped_by_wait(self).perform_later(self, *arguments, **options)
|
49
60
|
end
|
50
61
|
RUBY
|
62
|
+
|
63
|
+
[method, :"#{method}_later#{suffix}"] # Ensure `private performs :some_method` privates both names.
|
51
64
|
end
|
52
65
|
end
|
53
66
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_job-performs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kasper Timm Hansen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: '0'
|
64
64
|
requirements: []
|
65
|
-
rubygems_version: 3.
|
65
|
+
rubygems_version: 3.4.19
|
66
66
|
signing_key:
|
67
67
|
specification_version: 4
|
68
68
|
summary: ActiveJob::Performs adds the `performs` macro to set up jobs by convention.
|