class SmartCore::Operation::InstanceBuilder

@api private @since 0.1.0

Attributes

operation[R]

@return [SmartCore::Operation]

@api private @since 0.1.0

Public Class Methods

call(operation) click to toggle source

@param operation [SmartCore::Operation] @return [void]

@api private @since 0.1.0

# File lib/smart_core/operation/instance_builder.rb, line 12
def call(operation)
  new(operation).call
end
new(operation) click to toggle source

@param operation [SmartCore::Operation] @return [void]

@api private @since 0.1.0

# File lib/smart_core/operation/instance_builder.rb, line 22
def initialize(operation)
  @operation = operation
end

Public Instance Methods

call() click to toggle source

@return [void]

@api private @since 0.1.0

# File lib/smart_core/operation/instance_builder.rb, line 30
def call
  make_operation_caller_yieldable
end

Private Instance Methods

make_operation_caller_yieldable() click to toggle source

@return [void]

@api private @since 0.1.0

# File lib/smart_core/operation/instance_builder.rb, line 46
def make_operation_caller_yieldable
  operation.singleton_class.prepend(Module.new do
    def call
      super.tap { |result| yield(result) if block_given? }
    rescue SmartCore::Operation::Result::Fatal::FatalError => error
      # NOTE: returns SmartCore::Operation::Result::Fatal instance
      error.__operation_result__.tap { |result| yield(result) if block_given? }
    end
  end)
end