Sha256: acbf37c9bf6668582e46b4f0165e3825000a2f47ded485b11f3aca6e0504b750

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Service
    module Plugins
      module CanHaveSteps
        module Entities
          class Method
            module Commands
              class DefineMethodInContainer < Support::Command
                include Support::Delegate

                attr_reader :method, :container, :index

                delegate :key, :name, to: :method

                def initialize(method:, container:, index:)
                  @method = method
                  @container = container
                  @index = index
                end

                def call
                  ##
                  # NOTE: Assignement in the beginning for easier debugging.
                  #
                  <<~RUBY.tap { |code| container.klass.class_eval(code, __FILE__, __LINE__ + 1) }
                    def #{name}
                      step, key, method_name = steps[#{index}], :#{key}, :#{name}

                      raise #{not_completed_step_error}.new(step: step, method_name: method_name) unless step.completed?

                      raise #{not_existing_step_result_data_attribute_error}.new(step: step, key: key) unless step.result.unsafe_data.has_attribute?(key)

                      step.result.unsafe_data[key]
                    end
                  RUBY

                  true
                end

                private

                def not_completed_step_error
                  <<~RUBY.chomp
                    ::ConvenientService::Service::Plugins::CanHaveSteps::Entities::Method::Errors::NotCompletedStep
                  RUBY
                end

                def not_existing_step_result_data_attribute_error
                  <<~RUBY.chomp
                    ::ConvenientService::Service::Plugins::CanHaveSteps::Entities::Method::Errors::NotExistingStepResultDataAttribute
                  RUBY
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
convenient_service-0.12.0 lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/define_method_in_container.rb
convenient_service-0.11.0 lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/define_method_in_container.rb