Class: SmartCore::Operation::Success

Inherits:
Result
  • Object
show all
Defined in:
lib/smart_core/operation/success.rb

Overview

Since:

  • 0.2.0

Instance Attribute Summary

Attributes inherited from Result

#__result_attributes__, #__result_options__

Instance Method Summary collapse

Methods inherited from Result

#custom?, #failure?

Constructor Details

#initialize(**result_options) ⇒ void

Parameters:

  • result_options (Hash<Symbol,Any>)

Since:

  • 0.2.0



11
12
13
14
15
# File 'lib/smart_core/operation/success.rb', line 11

def initialize(**result_options)
  __prevent_method_overlapping__(result_options)
  super(**result_options) # NOTE: initialize result object
  __define_virtual_result_data_accessors__(result_options)
end

Instance Method Details

#success? {|nil| ... } ⇒ Boolean

Yields:

  • (nil)

Returns:

  • (Boolean)

Since:

  • 0.2.0



22
23
24
# File 'lib/smart_core/operation/success.rb', line 22

def success?
  true.tap { yield(self) if block_given? }
end

#to_hHash Also known as: to_hash

Support for operations like ‘result.success? { |**result| …result-as-a-hash… }`

Returns:

  • (Hash)

Since:

  • 0.5.0



32
33
34
# File 'lib/smart_core/operation/success.rb', line 32

def to_h
  __result_options__.dup
end