Skip to content

Commit a713b23

Browse files
authored
Merge branch 'main' into dependabot/bundler/rdoc-6.6.3.1
2 parents d349fe4 + 71ab123 commit a713b23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+654
-170
lines changed

.github/workflows/main.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
ruby:
18-
- '3.3.0'
19-
- '3.2.2'
20-
- '3.1.4'
18+
- '3.3.3'
19+
- '3.2.4'
20+
- '3.1.6'
2121
appraisal:
2222
- 'railties-7-sidekiq'
2323
- 'railties-6-sidekiq'
@@ -36,12 +36,14 @@ jobs:
3636
run: bundle exec appraisal install
3737
- name: Run the specs for Appraisal
3838
env:
39+
COVERAGE: true
3940
APPRAISAL: ${{ matrix.appraisal }}
4041
RUBY_VERSION: ${{ matrix.ruby }}
4142
run: bundle exec appraisal ${{ matrix.appraisal }} rake spec
4243
- name: Upload coverage reports to Codecov
4344
uses: codecov/codecov-action@v3
4445
env:
46+
COVERAGE: true
4547
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
4648
with:
4749
files: ./coverage/${{ matrix.ruby }}-${{ matrix.appraisal }}/coverage.json

CHANGELOG.md

+21-25
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,33 @@
11
## [Unreleased]
2+
- Add support for `Interactify.with(queue: 'within_30_seconds', retry: 3)`
23

3-
## [0.1.0-alpha.1] - 2023-12-16
4-
5-
- Initial release
6-
7-
## [0.2.0-alpha.1] - 2023-12-27
4+
## [0.5.0] - 2024-01-01
5+
- Add support for `SetA = Interactify { _1.a = 'a' }`, lambda and block class creation syntax
6+
- Add support for organizing `organize A.organizing(B, C, D), E, F` contract syntax
7+
- make definition errors raise optionally
8+
- raise an error with unexpected keys in Interactify.if clause
9+
- propagate caller_info through chains
810

9-
- Added support for Interactify.promising syntax in organizers
11+
## [0.4.1] - 2023-12-29
12+
- Fix bug triggered when nesting each and if
1013

11-
## [0.3.0-alpha.1] - 2023-12-29
14+
## [0.4.0] - 2023-12-29
15+
- All internal restructuring/refactoring into domains.
16+
- Add support for organize `self.if(:condition, then: A, else: B)` syntax
17+
- change location of matchers to `require 'interactify/rspec_matchers/matchers'`
1218

13-
- Added support for `{if: :condition, then: A, else: B}` in organizers
19+
## [0.3.0-RC1] - 2023-12-29
20+
- Fixed to work with and make optional dependencies for sidekiq and railties. Confirmed as working with ruby >= 3.1.4
1421

1522
## [0.3.0-alpha.2] - 2023-12-29
16-
1723
- Remove deep_matching development dependency
1824

19-
## [0.3.0-RC1] - 2023-12-29
20-
21-
- Fixed to work with and make optional dependencies for sidekiq and railties. Confirmed as working with ruby >= 3.1.4
2225

23-
## [0.4.0] - 2023-12-29
24-
25-
- All internal restructuring/refactoring into domains.
26-
- Add support for organize `self.if(:condition, then: A, else: B)` syntax
27-
- change location of matchers to `require 'interactify/rspec_matchers/matchers'`
26+
## [0.3.0-alpha.1] - 2023-12-29
27+
- Added support for `{if: :condition, then: A, else: B}` in organizers
2828

29-
## [0.4.1] - 2023-12-29
30-
- Fix bug triggered when nesting each and if
29+
## [0.2.0-alpha.1] - 2023-12-27
30+
- Added support for Interactify.promising syntax in organizers
3131

32-
## [0.5.0] - 2024-01-01
33-
- Add support for `SetA = Interactify { _1.a = 'a' }`, lambda and block class creation syntax
34-
- Add support for organizing `organize A.organizing(B, C, D), E, F` contract syntax
35-
- make definition errors raise optionally
36-
- raise an error with unexpected keys in Interactify.if clause
37-
- propagate caller_info through chains
32+
## [0.1.0-alpha.1] - 2023-12-16
33+
- Initial release

README.md

+53
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,26 @@ class LoadOrder
108108
end
109109
```
110110

111+
#### filled: false
112+
Both expect and promise can take the optional parameter `filled: false`
113+
This means that whilst the key is expected to be passed, it doesn't have to have a truthy or present value.
114+
Use this where valid values include, `[]`, `""`, `nil` or `false` etc.
115+
116+
117+
#### optional
118+
119+
```ruby
120+
class LoadOrder
121+
include Interactify
122+
123+
optional :some_key, :another_key
124+
end
125+
```
126+
127+
Optional can be used to denote that the key is not required to be passed.
128+
This is effectively equivalent to `delegate :key, to: :context`, but does not require the key to be present in the context.
129+
This is not recommended as the keys will not be validated by the contract or the interactor wiring specs.
130+
111131

112132
### Lambdas
113133

@@ -467,6 +487,39 @@ By using it's internal Async class.
467487
> [!CAUTION]
468488
> As your class is now executing asynchronously you can no longer rely on its promises later on in the chain.
469489
490+
491+
### Sidekiq options
492+
```ruby
493+
class SomeInteractor
494+
include Interactify.with(queue: 'within_30_seconds')
495+
end
496+
```
497+
498+
This allows you to set the sidekiq options for the asyncified interactor.
499+
It will autogenerate a class name that has the options set.
500+
501+
`SomeInteractor::Job__Queue_Within30Seconds` or with a random number suffix
502+
if there is a naming clash.
503+
504+
`SomeInteractor::Job__Queue_Within30Seconds_5342`
505+
506+
This is also aliased as `SomeInteractor::Job` for convenience.
507+
508+
An almost equivalent to the above without the `.with` method is:
509+
510+
```ruby
511+
class SomeInteractor
512+
include Interactify
513+
514+
class JobWithin30Seconds < Job
515+
sidekiq_options queue: 'within_30_seconds'
516+
end
517+
end
518+
```
519+
520+
Here the JobWithin30Seconds class is manually set up and subclasses the one
521+
automatically created by `include Interactify`.
522+
470523
## FAQs
471524
- This is ugly isn't it?
472525

gemfiles/no_railties_no_sidekiq.gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ group :test do
1313
gem "debug"
1414
gem "rspec", "~> 3.0"
1515
gem "simplecov", require: false
16+
gem "simplecov-json", require: false
1617
end
1718

1819
gemspec path: "../"

gemfiles/no_railties_no_sidekiq.gemfile.lock

+5
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ GEM
7676
irb (1.11.0)
7777
rdoc
7878
reline (>= 0.3.8)
79+
json (2.7.1)
7980
minitest (5.20.0)
8081
mutex_m (0.2.0)
8182
psych (5.1.2)
@@ -104,6 +105,9 @@ GEM
104105
simplecov-html (~> 0.11)
105106
simplecov_json_formatter (~> 0.1)
106107
simplecov-html (0.12.3)
108+
simplecov-json (0.2.3)
109+
json
110+
simplecov
107111
simplecov_json_formatter (0.1.4)
108112
stringio (3.1.0)
109113
thor (1.3.0)
@@ -122,6 +126,7 @@ DEPENDENCIES
122126
rake (~> 13.0)
123127
rspec (~> 3.0)
124128
simplecov
129+
simplecov-json
125130

126131
BUNDLED WITH
127132
2.4.22

gemfiles/railties_6_no_sidekiq.gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ group :test do
1414
gem "debug"
1515
gem "rspec", "~> 3.0"
1616
gem "simplecov", require: false
17+
gem "simplecov-json", require: false
1718
end
1819

1920
gemspec path: "../"

gemfiles/railties_6_no_sidekiq.gemfile.lock

+5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ GEM
8383
irb (1.11.0)
8484
rdoc
8585
reline (>= 0.3.8)
86+
json (2.7.1)
8687
loofah (2.22.0)
8788
crass (~> 1.0.2)
8889
nokogiri (>= 1.12.0)
@@ -134,6 +135,9 @@ GEM
134135
simplecov-html (~> 0.11)
135136
simplecov_json_formatter (~> 0.1)
136137
simplecov-html (0.12.3)
138+
simplecov-json (0.2.3)
139+
json
140+
simplecov
137141
simplecov_json_formatter (0.1.4)
138142
stringio (3.1.0)
139143
thor (1.3.0)
@@ -154,6 +158,7 @@ DEPENDENCIES
154158
rake (~> 13.0)
155159
rspec (~> 3.0)
156160
simplecov
161+
simplecov-json
157162

158163
BUNDLED WITH
159164
2.4.22

gemfiles/railties_6_sidekiq.gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ group :test do
1515
gem "debug"
1616
gem "rspec", "~> 3.0"
1717
gem "simplecov", require: false
18+
gem "simplecov-json", require: false
1819
end
1920

2021
gemspec path: "../"

gemfiles/railties_6_sidekiq.gemfile.lock

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ GEM
8484
irb (1.11.0)
8585
rdoc
8686
reline (>= 0.3.8)
87+
json (2.7.1)
8788
loofah (2.22.0)
8889
crass (~> 1.0.2)
8990
nokogiri (>= 1.12.0)
@@ -142,6 +143,9 @@ GEM
142143
simplecov-html (~> 0.11)
143144
simplecov_json_formatter (~> 0.1)
144145
simplecov-html (0.12.3)
146+
simplecov-json (0.2.3)
147+
json
148+
simplecov
145149
simplecov_json_formatter (0.1.4)
146150
stringio (3.1.0)
147151
thor (1.3.0)
@@ -163,6 +167,7 @@ DEPENDENCIES
163167
rspec (~> 3.0)
164168
sidekiq (= 7)
165169
simplecov
170+
simplecov-json
166171

167172
BUNDLED WITH
168173
2.4.22

gemfiles/railties_7_no_sidekiq.gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ group :test do
1414
gem "debug"
1515
gem "rspec", "~> 3.0"
1616
gem "simplecov", require: false
17+
gem "simplecov-json", require: false
1718
end
1819

1920
gemspec path: "../"

gemfiles/railties_7_no_sidekiq.gemfile.lock

+5
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ GEM
8282
irb (1.11.0)
8383
rdoc
8484
reline (>= 0.3.8)
85+
json (2.7.1)
8586
loofah (2.22.0)
8687
crass (~> 1.0.2)
8788
nokogiri (>= 1.12.0)
@@ -134,6 +135,9 @@ GEM
134135
simplecov-html (~> 0.11)
135136
simplecov_json_formatter (~> 0.1)
136137
simplecov-html (0.12.3)
138+
simplecov-json (0.2.3)
139+
json
140+
simplecov
137141
simplecov_json_formatter (0.1.4)
138142
stringio (3.1.0)
139143
thor (1.3.0)
@@ -153,6 +157,7 @@ DEPENDENCIES
153157
rake (~> 13.0)
154158
rspec (~> 3.0)
155159
simplecov
160+
simplecov-json
156161

157162
BUNDLED WITH
158163
2.4.22

gemfiles/railties_7_sidekiq.gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ group :test do
1515
gem "debug"
1616
gem "rspec", "~> 3.0"
1717
gem "simplecov", require: false
18+
gem "simplecov-json", require: false
1819
end
1920

2021
gemspec path: "../"

gemfiles/railties_7_sidekiq.gemfile.lock

+5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ GEM
8383
irb (1.11.0)
8484
rdoc
8585
reline (>= 0.3.8)
86+
json (2.7.1)
8687
loofah (2.22.0)
8788
crass (~> 1.0.2)
8889
nokogiri (>= 1.12.0)
@@ -142,6 +143,9 @@ GEM
142143
simplecov-html (~> 0.11)
143144
simplecov_json_formatter (~> 0.1)
144145
simplecov-html (0.12.3)
146+
simplecov-json (0.2.3)
147+
json
148+
simplecov
145149
simplecov_json_formatter (0.1.4)
146150
stringio (3.1.0)
147151
thor (1.3.0)
@@ -162,6 +166,7 @@ DEPENDENCIES
162166
rspec (~> 3.0)
163167
sidekiq (= 7)
164168
simplecov
169+
simplecov-json
165170

166171
BUNDLED WITH
167172
2.4.22

lib/interactify.rb

+13-33
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
require "interactify/dependency_inference"
1515
require "interactify/hooks"
1616
require "interactify/configure"
17+
require "interactify/with_options"
1718

1819
module Interactify
1920
extend ActiveSupport::Concern
@@ -22,39 +23,18 @@ module Interactify
2223

2324
class << self
2425
delegate :root, to: :configuration
25-
end
26-
27-
included do |base|
28-
base.extend Interactify::Dsl
29-
30-
base.include Interactor::Organizer
31-
base.include Interactor::Contracts
32-
base.include Interactify::Contracts::Helpers
33-
34-
# defines two classes on the receiver class
35-
# the first is the job class
36-
# the second is the async class
37-
# the async class is a wrapper around the job class
38-
# that allows it to be used in an interactor chain
39-
#
40-
# E.g.
41-
#
42-
# class ExampleInteractor
43-
# include Interactify
44-
# expect :foo
45-
# end
46-
#
47-
# ExampleInteractor::Job is a class availabe to be used in a sidekiq yaml file
48-
#
49-
# doing the following will immediately enqueue a job
50-
# that calls the interactor ExampleInteractor with (foo: 'bar')
51-
#
52-
# ExampleInteractor::Async.call(foo: 'bar')
53-
include Interactify::Async::Jobable
54-
interactor_job
55-
end
5626

57-
def called_klass_list
58-
context._called.map(&:class)
27+
def included(base)
28+
# call `with` without arguments to get default Job and Async classes
29+
base.include(with)
30+
end
31+
32+
def with(sidekiq_opts = {})
33+
Module.new do
34+
define_singleton_method :included do |receiver|
35+
WithOptions.new(receiver, sidekiq_opts).setup
36+
end
37+
end
38+
end
5939
end
6040
end

lib/interactify/async/job_klass.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def args(context)
5151
end
5252

5353
def restrict_to_optional_or_keys_from_contract(args)
54-
keys = container_klass.expected_keys.map(&:to_s)
54+
keys = Array(container_klass.expected_keys).map(&:to_s)
5555

5656
optional = Array(container_klass.optional_attrs).map(&:to_s)
5757
keys += optional

0 commit comments

Comments
 (0)