Sha256: 5110868f27d318b03ce8be9e3cd70cda7cd85c237139e0164b4679dde693de51

Contents?: true

Size: 535 Bytes

Versions: 11

Compression:

Stored size: 535 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?
          nil
        else
          output
        end
      end

    end # NullifyBlank

  end # Attribute
end # Virtus

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
tracker_api-1.7.1 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.7.0 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.6.0 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.5.0 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.4.1 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.4.0 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.3.0 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.2.1 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.1.1 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.1.0 lib/virtus/attribute/nullify_blank.rb
tracker_api-1.0.0 lib/virtus/attribute/nullify_blank.rb