active_job-performs 0.1.1 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d8648f755507d3bec0ae72e16af2382c925fa488ac19ee6db64ba7ddc25db63
4
- data.tar.gz: 67dd04fef65c5a107a59a9f89af5a5c437fc5f686613ac7ed505fb7afac09ddc
3
+ metadata.gz: afad0c3e092f329deb71fea10b4f2105d1a2fbff2d581eb46304411c8cf5c592
4
+ data.tar.gz: ec2db477f5e639b8dd8f4e1958f2f2813e9d32a85b6526693878a10927da6f0a
5
5
  SHA512:
6
- metadata.gz: c577b88ae29756cd24203b6ec98af0910bbcddf66faf444fd225bae7a257996084ac292a3b418518a20847749abb8b31c5fe5bde65a2c61eb4534194aa81e7e7
7
- data.tar.gz: 9f604e7ce1a7dc7fe0289b592f1e3dd859d2b96874c1fbb8cbfe008a9fb5ca1e2fa7ee4d133634552d29bfadb5fb146422524c99d89c00e1edf335a69f6c40ef
6
+ metadata.gz: 0213fcbdd14ecc60adbbff93d2f515b1ec1dee6f9511d9b69037ac2e85610cbaa9b3458a0b5256cba2f18f2d5e3f814dddf04e2993e89e3b0e44151b0cbc5819
7
+ data.tar.gz: 6bf98a858966a833b872643a3fc5b33f23d27d1499eaf8b917f5c470bb43b49cd2e8c68c8f0cad251714a84c7da2a531d4809e72b8db364818a8d76bbe827107
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.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_job-performs (0.1.1)
4
+ active_job-performs (0.2.0)
5
5
  activejob (>= 6.1)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -91,6 +91,44 @@ class Post < ActiveRecord::Base
91
91
  end
92
92
  ```
93
93
 
94
+ #### Method suffixes
95
+
96
+ `ActiveJob::Performs` supports Ruby's stylistic method suffixes, i.e. ? and ! respectively.
97
+
98
+ ```ruby
99
+ class Post < ActiveRecord::Base
100
+ performs :publish! # Generates `publish_later!` which calls `publish!`.
101
+ performs :retract? # Generates `retract_later?` which calls `retract?`.
102
+
103
+ def publish!
104
+
105
+ end
106
+
107
+ def retract?
108
+
109
+ end
110
+ end
111
+ ```
112
+
113
+ #### Private methods
114
+
115
+ `ActiveJob::Performs` also works with private methods in case you only want to expose the generated `_later` method.
116
+
117
+ ```ruby
118
+ class Post < ActiveRecord::Base
119
+ performs :publish # Generates the public `publish_later` instance method.
120
+
121
+ # Private implementation, only call `publish_later` please!
122
+ private def publish
123
+
124
+ end
125
+ end
126
+ ```
127
+
128
+ 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`.
129
+
130
+ E.g. `private performs :some_method` will generate a private `some_method_later` method.
131
+
94
132
  ### Usage with ActiveRecord::AssociatedObject
95
133
 
96
134
  The [`ActiveRecord::AssociatedObject`](https://github.com/kaspth/active_record-associated_object) gem also implements `GlobalID::Identification`, so you can do this too:
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveJob
4
4
  module Performs
5
- VERSION = "0.1.1"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
@@ -34,17 +34,20 @@ 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.#{method}(*arguments, **options)
45
+ object.send(:#{method}#{suffix}, *arguments, **options)
43
46
  end
44
47
  RUBY
45
48
 
46
49
  class_eval <<~RUBY, __FILE__, __LINE__ + 1
47
- def #{method}_later(*arguments, **options)
50
+ def #{method}_later#{suffix}(*arguments, **options)
48
51
  #{job}.scoped_by_wait(self).perform_later(self, *arguments, **options)
49
52
  end
50
53
  RUBY
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.1.1
4
+ version: 0.2.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: 2022-09-27 00:00:00.000000000 Z
11
+ date: 2023-01-12 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.3.21
65
+ rubygems_version: 3.4.1
66
66
  signing_key:
67
67
  specification_version: 4
68
68
  summary: ActiveJob::Performs adds the `performs` macro to set up jobs by convention.