Sha256: 643e61b48dfb831f0bfdb74dd6ccbe909e619d181af25c943571e30cea1d2d04

Contents?: true

Size: 781 Bytes

Versions: 3

Compression:

Stored size: 781 Bytes

Contents

require 'hermod/validators/base'

module Hermod
  module Validators
    # Checks the attributes are in a list of allowed attributes
    class Attributes < Base
      attr_reader :allowed_attributes

      # Public: Sets up the list of allowed attributes
      def initialize(allowed_attributes)
        @allowed_attributes = allowed_attributes
      end

      private

      def bad_attributes(attributes)
        attributes.map do |attribute, _|
          attribute unless allowed_attributes.include? attribute
        end.compact
      end

      def test(value, attributes)
        bad_attributes(attributes) == []
      end

      def message(value, attributes)
        "has attributes it doesn't accept: #{bad_attributes(attributes).to_sentence}"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hermod-3.0.0 lib/hermod/validators/attributes.rb
hermod-2.7.0 lib/hermod/validators/attributes.rb
hermod-2.7.0.pre.rc.1 lib/hermod/validators/attributes.rb