@@ -28,79 +28,36 @@ def included(base)
28
28
base . include Interactify ::WithDefaultJob
29
29
end
30
30
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 = { } )
49
32
sidekiq_opts = sidekiq_opts . symbolize_keys
50
33
klass_name = Async ::JobMaker ::VALID_KEYS . map do |key |
51
34
next unless sidekiq_opts . key? ( key )
52
35
53
36
"__#{ key . to_s . camelize } _#{ sidekiq_opts [ key ] . to_s . camelize } "
54
37
end . compact . join
55
38
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
+ )
61
46
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 : )
66
51
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
77
55
end
78
56
end
79
-
80
- mod
81
57
end
82
58
end
83
59
84
60
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')
104
61
def self . included ( base )
105
62
base . include Interactify ::Core
106
63
base . include Interactify ::Async ::Jobable
0 commit comments