Sha256: 134dfd7bafe36b9201d591508613e5f50007eb0401cba217a70559579cae0287

Contents?: true

Size: 409 Bytes

Versions: 4

Compression:

Stored size: 409 Bytes

Contents

module Hashme
  module Validations
    class CastedAttributeValidator < ActiveModel::EachValidator
      
      def validate_each(document, attribute, value)
        is_array = value.is_a?(Array) || value.is_a?(CastedArray)
        values = is_array ? value : [value]
        return if values.collect {|attr| attr.nil? || attr.valid? }.all?
        document.errors.add(attribute)
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hashme-0.2.6 lib/hashme/validations/casted_attribute_validator.rb
hashme-0.2.5 lib/hashme/validations/casted_attribute_validator.rb
hashme-0.2.4 lib/hashme/validations/casted_attribute_validator.rb
hashme-0.2.3 lib/hashme/validations/casted_attribute_validator.rb