Class: UseCases::StepActiveJobAdapter
- Inherits:
-
ActiveJob::Base
- Object
- ActiveJob::Base
- UseCases::StepActiveJobAdapter
- Defined in:
- lib/use_cases/step_active_job_adapter.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.serialize_step_arguments(args) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/use_cases/step_active_job_adapter.rb', line 26 def self.serialize_step_arguments(args) args.select.map.with_index do |arg, index| ActiveJob::Arguments.send(:serialize_argument, arg) rescue ActiveJob::SerializationError => _e arg.serialize.merge("_serialized_by_use_case" => true, "_class" => arg.class.name) rescue NoMethodError => _e puts "[WARNING] #{arg} of class (#{arg.clas}) (index = #{index})" \ "is not serializable and does not repond to #serialize and will be ignored." else arg end end |
Instance Method Details
#deserialize_step_arguments(args) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/use_cases/step_active_job_adapter.rb', line 16 def deserialize_step_arguments(args) args.map do |arg| if arg.is_a?(Hash) && arg.delete("_serialized_by_use_case") arg.delete("_class").constantize.new(arg) else arg end end end |
#perform(use_case_name, step_name, *args) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/use_cases/step_active_job_adapter.rb', line 9 def perform(use_case_name, step_name, *args) args = deserialize_step_arguments(args) use_case = ActiveSupport::Inflector.constantize(use_case_name) use_case.new.send(step_name, *args) end |