class SmartCore::Operation::Result::Success

@api public @since 0.1.0

Public Class Methods

new(**result_options) click to toggle source

@param result_options [Hash<Symbol,Any>] @return [void]

@api public @since 0.1.0

# File lib/smart_core/operation/result/success.rb, line 11
def initialize(**result_options)
  __prevent_core_methods_overlapping__(result_options)
  super(result_options)
  __define_virtual_acessors__(result_options)
end

Public Instance Methods

success?() { |self| ... } click to toggle source

@yield [SmartCore::Operation::Result::Success] @return [Boolean]

@api public @since 0.1.0

# File lib/smart_core/operation/result/success.rb, line 22
def success?
  true.tap { yield(self) if block_given? }
end
to_h() click to toggle source

@return [Hash<Symbol,Any>]

@api public @since 0.1.0

# File lib/smart_core/operation/result/success.rb, line 30
def to_h
  __result_options__.dup
end
Also aliased as: to_hash
to_hash()
Alias for: to_h

Private Instance Methods

__define_virtual_acessors__(result_options) click to toggle source

@param result_options [Hash<Symbol,Any>] @return [void]

@api private @since 0.1.0

# File lib/smart_core/operation/result/success.rb, line 59
def __define_virtual_acessors__(result_options)
  result_options.each_key do |result_attribute_name|
    define_singleton_method(result_attribute_name) do
      result_options[result_attribute_name]
    end
  end
end
__prevent_core_methods_overlapping__(result_options) click to toggle source

@param result_options [Hash<Symbol,Any>] @return [void]

@api private @since 0.1.0

# File lib/smart_core/operation/result/success.rb, line 42
  def __prevent_core_methods_overlapping__(result_options)
    overlappings = result_options.each_key.each_with_object([]) do |key, overlap|
      overlap << key if self.class.____core_methods____.include?(key)
    end

    if overlappings.any?
      raise(SmartCore::Operation::ResultCoreMethodOverlapError, <<~ERROR_MESSAGE)
        Result keys can not overlap core methods (operlapped keys: #{overlappings.join(', ')}).
      ERROR_MESSAGE
    end
  end