Sha256: 4f338c085ca211de23c88da9b5d79a067137bd7950ea1e93fd1d6688b44adfec

Contents?: true

Size: 1.52 KB

Versions: 7

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

# @api private
# @since 0.2.0
class SmartCore::Types::Primitive::Validator::Result
  # @return [Array]
  #
  # @api private
  # @since 0.2.0
  NO_INVARIANT_ERRORS = [].freeze

  # @return [SmartCore::Types::Primitive]
  #
  # @api public
  # @since 0.2.0
  attr_reader :type

  # @return [Boolean]
  #
  # @api public
  # @since 0.2.0
  attr_reader :is_valid_check
  alias_method :valid_check?, :is_valid_check

  # @return [Any]
  #
  # @api public
  # @since 0.2.0
  attr_reader :checked_value
  alias_method :value, :checked_value

  # @return [Array<String>]
  #
  # @api public
  # @since 0.2.0
  attr_reader :invariant_errors
  alias_method :errors, :invariant_errors
  alias_method :error_codes, :invariant_errors

  # @param type [SmartCore::Types::Primitive]
  # @param checked_value [Any]
  # @param is_valid_check [Boolean]
  # @param invariant_errors [Array<String>]
  # @return [void]
  #
  # @api private
  # @since 0.2.0
  def initialize(type, checked_value, is_valid_check, invariant_errors = NO_INVARIANT_ERRORS.dup)
    @type = type
    @checked_value = checked_value
    @is_valid_check = is_valid_check
    @invariant_errors = invariant_errors.tap(&:freeze)
  end

  # @return [Boolean]
  #
  # @api public
  # @since 0.2.0
  def valid_invariants?
    invariant_errors.empty?
  end

  # @return [Boolean]
  #
  # @api public
  # @since 0.2.0
  def success?
    valid_check? && invariant_errors.empty?
  end

  # @return [Boolean]
  #
  # @api public
  # @since 0.2.0
  def failure?
    !success?
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
smart_types-0.8.0 lib/smart_core/types/primitive/validator/result.rb
smart_types-0.7.1 lib/smart_core/types/primitive/validator/result.rb
smart_types-0.7.0 lib/smart_core/types/primitive/validator/result.rb
smart_types-0.6.0 lib/smart_core/types/primitive/validator/result.rb
smart_types-0.4.0 lib/smart_core/types/primitive/validator/result.rb
smart_types-0.3.0 lib/smart_core/types/primitive/validator/result.rb
smart_types-0.2.0 lib/smart_core/types/primitive/validator/result.rb