Sha256: b64812b55affd5d151c942d1661efe6073f59d35b827a282f2eec31abd9044c2

Contents?: true

Size: 566 Bytes

Versions: 7

Compression:

Stored size: 566 Bytes

Contents

# frozen_string_literal: true

module Grape
  module Validations
    class SingleAttributeIterator < AttributesIterator
      private

      def yield_attributes(val, attrs)
        attrs.each do |attr_name|
          yield val, attr_name, empty?(val)
        end
      end

      # Primitives like Integers and Booleans don't respond to +empty?+.
      # It could be possible to use +blank?+ instead, but
      #
      #     false.blank?
      #     => true
      def empty?(val)
        val.respond_to?(:empty?) ? val.empty? : val.nil?
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
grape-1.5.0 lib/grape/validations/single_attribute_iterator.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.4.0/lib/grape/validations/single_attribute_iterator.rb
grape-1.4.0 lib/grape/validations/single_attribute_iterator.rb
grape-1.3.3 lib/grape/validations/single_attribute_iterator.rb
grape-1.3.2 lib/grape/validations/single_attribute_iterator.rb
grape-1.3.1 lib/grape/validations/single_attribute_iterator.rb
grape-1.3.0 lib/grape/validations/single_attribute_iterator.rb