Module: RSchema::Coercers::NilEmptyStrings

Extended by:
NilEmptyStrings
Included in:
NilEmptyStrings
Defined in:
lib/rschema/coercers/nil_empty_strings.rb

Overview

Coerces empty strings to nil

Instance Method Summary collapse

Instance Method Details

#build(_schema) ⇒ Object


11
12
13
# File 'lib/rschema/coercers/nil_empty_strings.rb', line 11

def build(_schema)
  self
end

#call(value) ⇒ Object


15
16
17
18
19
20
21
# File 'lib/rschema/coercers/nil_empty_strings.rb', line 15

def call(value)
  if value == ''
    Result.success(nil)
  else
    Result.success(value)
  end
end

#will_affect?(value) ⇒ Boolean

Returns:


23
24
25
# File 'lib/rschema/coercers/nil_empty_strings.rb', line 23

def will_affect?(value)
  value == ''
end