Sha256: 2a30f0f958f8cde6dbc3247ed8ff20a335fa09e4e7a8bf6d4d2aa7bdf65fc965

Contents?: true

Size: 806 Bytes

Versions: 9

Compression:

Stored size: 806 Bytes

Contents

# frozen_string_literal: true

require "pakyow/support/core_refinements/array/ensurable"

require "pakyow/validator"

module Pakyow
  module Validations
    # Ensures that the given value matches an acceptance value. By default, the value must equal
    # +true+. Use the `accepts` keyword argument to pass one or more comparison values.
    #
    # @example
    #   validate :acceptance
    #
    # @example
    #   validate :acceptance, accepts: ["yes", "y"]
    #
    # @api public
    module Acceptance
      using Support::Refinements::Array::Ensurable

      def self.message(**)
        "must be accepted"
      end

      def self.valid?(value, accepts: true, **)
        Array.ensure(accepts).include?(value)
      end
    end

    Validator.register_validation(Acceptance, :acceptance)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pakyow-core-1.0.6 lib/pakyow/validations/acceptance.rb
pakyow-core-1.0.5 lib/pakyow/validations/acceptance.rb
pakyow-core-1.0.4 lib/pakyow/validations/acceptance.rb
pakyow-core-1.0.3 lib/pakyow/validations/acceptance.rb
pakyow-core-1.0.2 lib/pakyow/validations/acceptance.rb
pakyow-core-1.0.1 lib/pakyow/validations/acceptance.rb
pakyow-core-1.0.0 lib/pakyow/validations/acceptance.rb
pakyow-core-1.0.0.rc5 lib/pakyow/validations/acceptance.rb
pakyow-core-1.0.0.rc4 lib/pakyow/validations/acceptance.rb