Class: ConvenientService::Service::Plugins::CanHaveSteps::Entities::Method::Commands::DefineMethodInContainer

Inherits:
ConvenientService::Support::Command show all
Includes:
ConvenientService::Support::Delegate
Defined in:
lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/define_method_in_container.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ConvenientService::Support::Concern

included

Methods inherited from ConvenientService::Support::Command

[], call

Constructor Details

#initialize(method:, container:, index:) ⇒ DefineMethodInContainer

Returns a new instance of DefineMethodInContainer.



17
18
19
20
21
# File 'lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/define_method_in_container.rb', line 17

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

Instance Attribute Details

#containerObject (readonly)

Returns the value of attribute container.



13
14
15
# File 'lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/define_method_in_container.rb', line 13

def container
  @container
end

#indexObject (readonly)

Returns the value of attribute index.



13
14
15
# File 'lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/define_method_in_container.rb', line 13

def index
  @index
end

#methodObject (readonly)

Returns the value of attribute method.



13
14
15
# File 'lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/define_method_in_container.rb', line 13

def method
  @method
end

Instance Method Details

#callObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/define_method_in_container.rb', line 23

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}

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

      ::ConvenientService.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