Sha256: 9ee091beb1f946bf75da4668f696d6d9b594074e50598141f17aef9f5393ee2c

Contents?: true

Size: 645 Bytes

Versions: 10

Compression:

Stored size: 645 Bytes

Contents

module DataMapper
  module Ext
    # Determines whether the specified +value+ is blank.
    #
    # An object is blank if it's false, empty, or a whitespace string.
    # For example, "", "   ", +nil+, [], and {} are blank.
    #
    # @api semipublic
    def self.blank?(value)
      return value.blank? if value.respond_to?(:blank?)
      case value
      when ::NilClass, ::FalseClass
        true
      when ::TrueClass, ::Numeric
        false
      when ::Array, ::Hash
        value.empty?
      when ::String
        value !~ /\S/
      else
        value.nil? || (value.respond_to?(:empty?) && value.empty?)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 4 rubygems

Version Path
sbf-dm-core-1.4.0 lib/dm-core/support/ext/blank.rb
sbf-dm-core-1.3.0 lib/dm-core/support/ext/blank.rb
sbf-dm-core-1.3.0.beta lib/dm-core/support/ext/blank.rb
ardm-core-1.3.0 lib/dm-core/support/ext/blank.rb
ardm-core-1.2.1 lib/dm-core/support/ext/blank.rb
dm-core-1.2.1 lib/dm-core/support/ext/blank.rb
ghost_dm-core-1.3.0.beta lib/dm-core/support/ext/blank.rb
dm-core-1.2.0 lib/dm-core/support/ext/blank.rb
dm-core-1.2.0.rc2 lib/dm-core/support/ext/blank.rb
dm-core-1.2.0.rc1 lib/dm-core/support/ext/blank.rb