All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gems.virtus-1.0.5.lib.virtus.attribute.nullify_blank.rb Maven / Gradle / Ivy

The newest version!
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.to_s.empty?
          nil
        else
          output
        end
      end

    end # NullifyBlank

  end # Attribute
end # Virtus




© 2015 - 2024 Weber Informatics LLC | Privacy Policy