Skip to content

Commit 1cc4c2b

Browse files
committed
remove need for passing self
1 parent 8414817 commit 1cc4c2b

File tree

4 files changed

+17
-61
lines changed

4 files changed

+17
-61
lines changed

CHANGELOG.md

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

44
## [0.5.0] - 2024-01-01
55
- Add support for `SetA = Interactify { _1.a = 'a' }`, lambda and block class creation syntax

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ By using it's internal Async class.
471471
### Sidekiq options
472472
```ruby
473473
class SomeInteractor
474-
include Interactify.with(self, queue: 'within_30_seconds')
474+
include Interactify.with(queue: 'within_30_seconds')
475475
end
476476
```
477477

lib/interactify.rb

+15-58
Original file line numberDiff line numberDiff line change
@@ -28,79 +28,36 @@ def included(base)
2828
base.include Interactify::WithDefaultJob
2929
end
3030

31-
# creates a module to include that
32-
# has specified sidekiq options
33-
#
34-
# E.g.
35-
#
36-
# class ExampleInteractor
37-
# include Interactify.with(self, queue: 'within_30_seconds', retries: 3)
38-
#
39-
# expect :foo
40-
# end
41-
#
42-
# creates
43-
# - ExampleInteractor::InteractifyWithOptions
44-
# - ExampleInteractor::JobWith__Queue_Within30Seconds__Retries_3
45-
# - ExampleInteractor::Job (an alias of above)
46-
# - ExampleInteractor::AsyncWith__Queue_Within30Seconds__Retries_3
47-
# - ExampleInteractor::Async (an alias of above)
48-
def with(receiver, sidekiq_opts = {})
31+
def with(sidekiq_opts = {})
4932
sidekiq_opts = sidekiq_opts.symbolize_keys
5033
klass_name = Async::JobMaker::VALID_KEYS.map do |key|
5134
next unless sidekiq_opts.key?(key)
5235

5336
"__#{key.to_s.camelize}_#{sidekiq_opts[key].to_s.camelize}"
5437
end.compact.join
5538

56-
klass_suffix = Dsl.unique_klass_name(
57-
namespace: receiver,
58-
klass_name: "With#{klass_name}",
59-
camelize: false
60-
)
39+
Module.new do
40+
define_singleton_method :included do |receiver|
41+
klass_suffix = Dsl.unique_klass_name(
42+
namespace: receiver,
43+
klass_name: "With#{klass_name}",
44+
camelize: false
45+
)
6146

62-
receiver.const_set(:InteractifyWithOptions, Module.new)
63-
mod = receiver.const_get(:InteractifyWithOptions)
64-
job_klass = nil
65-
async_klass = nil
47+
receiver.instance_eval do
48+
include Interactify::Core
49+
include Interactify::Async::Jobable
50+
interactor_job(opts: sidekiq_opts, klass_suffix:)
6651

67-
mod.instance_eval do
68-
define_singleton_method :included do |base|
69-
base.include Interactify::Core
70-
base.include Interactify::Async::Jobable
71-
72-
base.interactor_job(opts: sidekiq_opts, klass_suffix:)
73-
job_klass = base.const_get :"Job#{klass_suffix}"
74-
async_klass = base.const_get :"Async#{klass_suffix}"
75-
receiver.const_set("Job", job_klass)
76-
receiver.const_set("Async", async_klass)
52+
const_set("Job", const_get(:"Job#{klass_suffix}"))
53+
const_set("Async", const_get(:"Async#{klass_suffix}"))
54+
end
7755
end
7856
end
79-
80-
mod
8157
end
8258
end
8359

8460
module WithDefaultJob
85-
# defines two classes on the receiver class
86-
# the first is the job class
87-
# the second is the async class
88-
# the async class is a wrapper around the job class
89-
# that allows it to be used in an interactor chain
90-
#
91-
# E.g.
92-
#
93-
# class ExampleInteractor
94-
# include Interactify
95-
# expect :foo
96-
# end
97-
#
98-
# ExampleInteractor::Job is a class availabe to be used in a sidekiq yaml file
99-
#
100-
# doing the following will immediately enqueue a job
101-
# that calls the interactor ExampleInteractor with (foo: 'bar')
102-
#
103-
# ExampleInteractor::Async.call(foo: 'bar')
10461
def self.included(base)
10562
base.include Interactify::Core
10663
base.include Interactify::Async::Jobable

spec/lib/interactify.with_spec.rb

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
module self::SomeNamespace
3434
class Optionified
3535
include Interactify.with(
36-
self,
3736
queue: 'within_30_seconds',
3837
retry: 3
3938
)

0 commit comments

Comments
 (0)