Module: DataMapper::Ext

Defined in:
lib/dm-core/support/ext/hash.rb,
lib/dm-core/support/ext/array.rb,
lib/dm-core/support/ext/blank.rb,
lib/dm-core/support/ext/module.rb,
lib/dm-core/support/ext/object.rb,
lib/dm-core/support/ext/string.rb,
lib/dm-core/support/ext/try_dup.rb

Defined Under Namespace

Modules: Array, Hash, Module, Object, String

Class Method Summary collapse

Class Method Details

.blank?(value) ⇒ Boolean

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.

Returns:

  • (Boolean)

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dm-core/support/ext/blank.rb', line 9

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

.try_dup(value) ⇒ Object


3
4
5
6
7
8
9
10
# File 'lib/dm-core/support/ext/try_dup.rb', line 3

def self.try_dup(value)
  case value
  when ::TrueClass, ::FalseClass, ::NilClass, ::Module, ::Numeric, ::Symbol
    value
  else
    value.dup
  end
end