Sha256: 0f78d9791093796d4f08c879822bf3119b44dc5808f89f5959ba371804575337

Contents?: true

Size: 695 Bytes

Versions: 3

Compression:

Stored size: 695 Bytes

Contents

# frozen_string_literal: true

module Attribool::Validators
  ##
  # Ensures that every item is an instance of +Attribool::Attribute+.
  class AttributeListValidator
    ##
    # Construct the validator.
    #
    # @param [Attribool::Attribute] *items
    def initialize(*items)
      @items = items
    end

    ##
    # Are all items an instance of +Attribool::Attribute+?
    #
    # @return [Boolean]
    def valid?
      @items.all?(Attribool::Attribute)
    end

    ##
    # The exception to raise if validations fail.
    #
    # @return [TypeError] the exception with message
    def error
      TypeError.new("All items must be an instance of Attribool::Attribute")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
attribool-2.0.5 lib/attribool/validators/attribute_list_validator.rb
attribool-2.0.4 lib/attribool/validators/attribute_list_validator.rb
attribool-2.0.3 lib/attribool/validators/attribute_list_validator.rb