Module: SimpleMapper::Attributes::Types::String

Defined in:
lib/simple_mapper/attributes/types.rb

Overview

Provides simple string type support.

Registered as :string.

This is intended to be quite flexible and rely purely on duck typing. It should work with any input that supports :to_s, and is not strictly limited to actual String instances.

Class Method Summary collapse

Class Method Details

.decode(value) ⇒ Object

Decodes value into a String object via the :to_s of value. Passes nils through unchanged. For the majority use case, most of the time the result and the input will be equal.



65
66
67
68
# File 'lib/simple_mapper/attributes/types.rb', line 65

def self.decode(value)
  return nil if value.nil?
  value.to_s
end

.defaultObject

Returns the empty string for a “default”.



78
79
80
# File 'lib/simple_mapper/attributes/types.rb', line 78

def self.default
  ''
end

.encode(value) ⇒ Object

Encodes value as a string via its :to_s method. Passes nils through unchanged.



72
73
74
75
# File 'lib/simple_mapper/attributes/types.rb', line 72

def self.encode(value)
  return nil if value.nil?
  value.to_s
end