Class: Steroids::Services::Base
Defined Under Namespace
Classes: AmbiguousProcessMethodError, AsyncProcessArgumentError, RuntimeError
Constant Summary
collapse
- @@wrap_in_transaction =
true
- @@skip_callbacks =
false
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.async? ⇒ Boolean
134
135
136
|
# File 'lib/steroids/services/base.rb', line 134
def async?
self.private_instance_methods.include?(:async_process) || self.instance_methods.include?(:async_process)
end
|
.call(*args, **options, &block) ⇒ Object
138
139
140
|
# File 'lib/steroids/services/base.rb', line 138
def call(*args, **options, &block)
new(*args, **options).call(&block)
end
|
.new(*arguments, **options) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/steroids/services/base.rb', line 142
def new(*arguments, **options)
validate_process_definition!
instance = super
if self.async?
if arguments.empty? && options.serializable?
instance.instance_variable_set(:"@_steroids_serialized_init_options", options.deep_serialize)
else
raise AsyncProcessArgumentError.new("Async services require serializable options")
end
end
instance
end
|
.steroids_after_callbacks ⇒ Object
159
160
161
|
# File 'lib/steroids/services/base.rb', line 159
def steroids_after_callbacks
@steroids_after_callbacks ||= []
end
|
.steroids_before_callbacks ⇒ Object
155
156
157
|
# File 'lib/steroids/services/base.rb', line 155
def steroids_before_callbacks
@steroids_before_callbacks ||= []
end
|
.validate_process_definition! ⇒ Object
163
164
165
166
167
|
# File 'lib/steroids/services/base.rb', line 163
def validate_process_definition!
if async? && (self.private_instance_methods.include?(:process) || self.instance_methods.include?(:process))
raise AmbiguousProcessMethodError.new("Can't define both `process` and `async_process`")
end
end
|
Instance Method Details
#call(*args, **options, &block) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/steroids/services/base.rb', line 22
def call(*args, **options, &block)
return unless process_method.present?
@steroids_force = (!!options[:force]) || false
@steroids_skip_callbacks = (!!options[:skip_callbacks]) || @@skip_callbacks || false
if process_method.name == :async_process
schedule_process(*args, **options, &block)
else
exec_process(*args, **options, &block)
end
end
|