Sha256: 90b22cb303e79e576426d0c8af698defe34e8f5ccb55250230d159f7976b54ea

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

# @api private
# @since 0.2.0
class SmartCore::Types::Primitive::InvariantControl::Chain::Result
  # @return [SmartCore::Types::Primitive::invariantControl::Chain]
  #
  # @api private
  # @since 0.2.0
  attr_reader :invariant_chain

  # @return [Any]
  #
  # @api private
  # @since 0.2.0
  attr_reader :checked_value

  # @param invariant_chain [SmartCore::Types::Primitive::invariantControl::Chain]
  # @param checked_value [Any]
  # @param invariant_results [Array<SmartCore::Types::Primitive::InvariantControl::Single::Result>]
  # @return [void]
  #
  # @api private
  # @since 0.2.0
  def initialize(invariant_chain, checked_value, invariant_results)
    @invariant_chain = invariant_chain
    @checked_value = checked_value
    @invariant_results = invariant_results
  end

  # @return [Boolean]
  #
  # @api private
  # @since 0.2.0
  def success?
    invariant_results.all?(&:success?)
  end

  # @return [Boolean]
  #
  # @api private
  # @since 0.2.0
  def failure?
    invariant_results.any?(&:failure?)
  end

  # @return [Array<String>]
  #
  # @api private
  # @since 0.1.0
  def error_codes
    invariant_results.select(&:failure?).map! do |invariant_result|
      "#{invariant_chain.name}.#{invariant_result.invariant.name}".tap(&:freeze)
    end
  end

  private

  # @return [Array<SmartCore::Types::Primitive::InvariantControl::Single::Result>]
  #
  # @api private
  # @since 0.2.0
  attr_reader :invariant_results
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smart_types-0.8.0 lib/smart_core/types/primitive/invariant_control/chain/result.rb