Class: Tasker::HandlerSerializer
- Inherits:
-
ActiveModel::Serializer
- Object
- ActiveModel::Serializer
- Tasker::HandlerSerializer
- Defined in:
- app/serializers/tasker/handler_serializer.rb
Instance Method Summary collapse
- #available ⇒ Object
- #class_name ⇒ Object
- #full_name ⇒ Object
-
#initialize(object, options = {}) ⇒ HandlerSerializer
constructor
A new instance of HandlerSerializer.
- #name ⇒ Object
- #namespace ⇒ Object
- #step_templates ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(object, options = {}) ⇒ HandlerSerializer
Returns a new instance of HandlerSerializer.
8 9 10 11 12 13 14 |
# File 'app/serializers/tasker/handler_serializer.rb', line 8 def initialize(object, = {}) @handler_name = [:handler_name] @namespace = [:namespace] || :default @version = [:version] || '0.1.0' @handler_class = object super end |
Instance Method Details
#available ⇒ Object
40 41 42 43 44 45 |
# File 'app/serializers/tasker/handler_serializer.rb', line 40 def available instantiate_handler true rescue StandardError false end |
#class_name ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/serializers/tasker/handler_serializer.rb', line 32 def class_name if @handler_class.is_a?(Class) @handler_class.name else @handler_class.to_s end end |
#full_name ⇒ Object
28 29 30 |
# File 'app/serializers/tasker/handler_serializer.rb', line 28 def full_name "#{namespace}.#{name}@#{version}" end |
#name ⇒ Object
16 17 18 |
# File 'app/serializers/tasker/handler_serializer.rb', line 16 def name @handler_name.to_s end |
#namespace ⇒ Object
20 21 22 |
# File 'app/serializers/tasker/handler_serializer.rb', line 20 def namespace @namespace.to_s end |
#step_templates ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/serializers/tasker/handler_serializer.rb', line 47 def step_templates return [] unless handler_instance begin templates = handler_instance.step_templates return [] unless templates.respond_to?(:map) templates.map do |template| template_hash = {} # Handle StepTemplate dry-struct attributes template_hash[:name] = template.name.to_s if template.respond_to?(:name) template_hash[:description] = template.description if template.respond_to?(:description) template_hash[:dependent_system] = template.dependent_system.to_s if template.respond_to?(:dependent_system) if template.respond_to?(:depends_on_step) && template.depends_on_step template_hash[:depends_on_step] = template.depends_on_step.to_s end template_hash[:depends_on_steps] = template.depends_on_steps if template.respond_to?(:depends_on_steps) # Handle handler class - could be Class object or string if template.respond_to?(:handler_class) template_hash[:handler_class] = template.handler_class.is_a?(Class) ? template.handler_class.name : template.handler_class.to_s end # Use the correct attribute name for configuration template_hash[:configuration] = template.handler_config if template.respond_to?(:handler_config) # Include dry-struct specific attributes template_hash[:default_retryable] = template.default_retryable if template.respond_to?(:default_retryable) if template.respond_to?(:default_retry_limit) template_hash[:default_retry_limit] = template.default_retry_limit end template_hash[:skippable] = template.skippable if template.respond_to?(:skippable) template_hash[:custom_events] = template.custom_events if template.respond_to?(:custom_events) template_hash end rescue StandardError => e Rails.logger.warn "Failed to introspect step templates for #{class_name}: #{e.}" [] end end |
#version ⇒ Object
24 25 26 |
# File 'app/serializers/tasker/handler_serializer.rb', line 24 def version @version.to_s end |