class SmartCore::Operation::Success
@api public @since 0.2.0
Public Class Methods
new(**result_options)
click to toggle source
@param result_options [Hash<Symbol,Any>] @return [void]
@api public @since 0.2.0
Calls superclass method
SmartCore::Operation::Result::new
# 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
Public Instance Methods
success?() { |self| ... }
click to toggle source
@yield [nil] @return [Boolean]
@api public @since 0.2.0
# File lib/smart_core/operation/success.rb, line 22 def success? true.tap { yield(self) if block_given? } end
to_h()
click to toggle source
Support for operations like `result.success? { |**result| …result-as-a-hash… }`
@return [Hash]
@api public @since 0.5.0
# File lib/smart_core/operation/success.rb, line 32 def to_h __result_options__.dup end
Also aliased as: to_hash
Private Instance Methods
__define_virtual_result_data_accessors__(result_options)
click to toggle source
@param result_options [Hash<Symbol,Any>] @return [void]
@api private @since 0.2.0
# File lib/smart_core/operation/success.rb, line 64 def __define_virtual_result_data_accessors__(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_method_overlapping__(result_options)
click to toggle source
@param result_options [Hash<Symbol,Any>] @return [void]
@raise [SmartCore::Operation::IncompatibleResultKeyError] @raise [SmartCore::Operation::ResultMethodIntersectionError]
@api private @since 0.2.0
# File lib/smart_core/operation/success.rb, line 47 def __prevent_method_overlapping__(result_options) overlappings = result_options.each_key.each_with_object([]) do |key, overlap| overlap << key if self.class.__core_methods__.include?(key) end raise( SmartCore::Operation::ResultMethodIntersectionError, "Result keys can not overlap core methods " \ "(overlapping keys: #{overlappings.join(', ')})." ) if overlappings.any? end