Sha256: 86d0ca09534181768f0eca6ddd062d2bea29460363566183c42383b90cad03f2

Contents?: true

Size: 554 Bytes

Versions: 10

Compression:

Stored size: 554 Bytes

Contents

module Virtus
  class Attribute

    # Attribute extension which nullifies blank attributes when coercion failed
    #
    module NullifyBlank

      # @see [Attribute#coerce]
      #
      # @api public
      def coerce(input)
        output = super

        if !value_coerced?(output) && input.blank?
          nil
        # Added to nullify anything that is blank not just strings.
        elsif output.blank? && output != false
          nil
        else
          output
        end
      end

    end # NullifyBlank

  end # Attribute
end # Virtus

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tracker_api-1.16.0 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.15.0 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.14.0 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.13.0 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.12.0 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.11.0 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.10.0 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.9.1 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.9.0 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.8.0 lib/virtus/attribute/nullify_blank.rb