Module: Lotus::Model::Mapping::Coercions

Defined in:
lib/lotus/model/mapping/coercions.rb

Overview

Coercions utilities

Since:

  • 0.1.1

Class Method Summary collapse

Class Method Details

.Array(arg) ⇒ Array

Coerce into an Array, unless the argument is nil

Parameters:

  • arg (Object)

    the object to coerce

Returns:

  • (Array)

    the result of the coercion

Raises:

  • (TypeError)

    if the argument can’t be coerced

See Also:

Since:

  • 0.1.1



21
22
23
# File 'lib/lotus/model/mapping/coercions.rb', line 21

def self.Array(arg)
  ::Kernel.Array(arg) unless arg.nil?
end

.BigDecimal(arg) ⇒ BigDecimal

Coerce into a BigDecimal, unless the argument is nil

Parameters:

  • arg (Object)

    the object to coerce

Returns:

Raises:

  • (TypeError)

    if the argument can’t be coerced

See Also:

Since:

  • 0.2.0



126
127
128
# File 'lib/lotus/model/mapping/coercions.rb', line 126

def self.BigDecimal(arg)
  Utils::Kernel.BigDecimal(arg) unless arg.nil?
end

.Boolean(arg) ⇒ Boolean

Coerce into a Boolean, unless the argument is nil

Parameters:

  • arg (Object)

    the object to coerce

Returns:

  • (Boolean)

    the result of the coercion

Raises:

  • (TypeError)

    if the argument can’t be coerced

See Also:

Since:

  • 0.1.1



36
37
38
# File 'lib/lotus/model/mapping/coercions.rb', line 36

def self.Boolean(arg)
  Utils::Kernel.Boolean(arg) unless arg.nil?
end

.Date(arg) ⇒ Date

Coerce into a Date, unless the argument is nil

Parameters:

  • arg (Object)

    the object to coerce

Returns:

  • (Date)

    the result of the coercion

Raises:

  • (TypeError)

    if the argument can’t be coerced

See Also:

Since:

  • 0.1.1



51
52
53
# File 'lib/lotus/model/mapping/coercions.rb', line 51

def self.Date(arg)
  Utils::Kernel.Date(arg) unless arg.nil?
end

.DateTime(arg) ⇒ DateTime

Coerce into a DateTime, unless the argument is nil

Parameters:

  • arg (Object)

    the object to coerce

Returns:

  • (DateTime)

    the result of the coercion

Raises:

  • (TypeError)

    if the argument can’t be coerced

See Also:

Since:

  • 0.1.1



66
67
68
# File 'lib/lotus/model/mapping/coercions.rb', line 66

def self.DateTime(arg)
  Utils::Kernel.DateTime(arg) unless arg.nil?
end

.Float(arg) ⇒ Float

Coerce into a Float, unless the argument is nil

Parameters:

  • arg (Object)

    the object to coerce

Returns:

  • (Float)

    the result of the coercion

Raises:

  • (TypeError)

    if the argument can’t be coerced

See Also:

Since:

  • 0.1.1



81
82
83
# File 'lib/lotus/model/mapping/coercions.rb', line 81

def self.Float(arg)
  Utils::Kernel.Float(arg) unless arg.nil?
end

.Hash(arg) ⇒ Hash

Coerce into a Hash, unless the argument is nil

Parameters:

  • arg (Object)

    the object to coerce

Returns:

  • (Hash)

    the result of the coercion

Raises:

  • (TypeError)

    if the argument can’t be coerced

See Also:

Since:

  • 0.1.1



96
97
98
# File 'lib/lotus/model/mapping/coercions.rb', line 96

def self.Hash(arg)
  Utils::Kernel.Hash(arg) unless arg.nil?
end

.Integer(arg) ⇒ Integer

Coerce into an Integer, unless the argument is nil

Parameters:

  • arg (Object)

    the object to coerce

Returns:

  • (Integer)

    the result of the coercion

Raises:

  • (TypeError)

    if the argument can’t be coerced

See Also:

Since:

  • 0.1.1



111
112
113
# File 'lib/lotus/model/mapping/coercions.rb', line 111

def self.Integer(arg)
  Utils::Kernel.Integer(arg) unless arg.nil?
end

.Set(arg) ⇒ Set

Coerce into a Set, unless the argument is nil

Parameters:

  • arg (Object)

    the object to coerce

Returns:

  • (Set)

    the result of the coercion

Raises:

  • (TypeError)

    if the argument can’t be coerced

See Also:

Since:

  • 0.1.1



141
142
143
# File 'lib/lotus/model/mapping/coercions.rb', line 141

def self.Set(arg)
  Utils::Kernel.Set(arg) unless arg.nil?
end

.String(arg) ⇒ String

Coerce into a String, unless the argument is nil

Parameters:

  • arg (Object)

    the object to coerce

Returns:

  • (String)

    the result of the coercion

Raises:

  • (TypeError)

    if the argument can’t be coerced

See Also:

Since:

  • 0.1.1



156
157
158
# File 'lib/lotus/model/mapping/coercions.rb', line 156

def self.String(arg)
  Utils::Kernel.String(arg) unless arg.nil?
end

.Symbol(arg) ⇒ Symbol

Coerce into a Symbol, unless the argument is nil

Parameters:

  • arg (Object)

    the object to coerce

Returns:

  • (Symbol)

    the result of the coercion

Raises:

  • (TypeError)

    if the argument can’t be coerced

See Also:

Since:

  • 0.2.0



171
172
173
# File 'lib/lotus/model/mapping/coercions.rb', line 171

def self.Symbol(arg)
  Utils::Kernel.Symbol(arg) unless arg.nil?
end

.Time(arg) ⇒ Time

Coerce into a Time, unless the argument is nil

Parameters:

  • arg (Object)

    the object to coerce

Returns:

  • (Time)

    the result of the coercion

Raises:

  • (TypeError)

    if the argument can’t be coerced

See Also:

Since:

  • 0.1.1



186
187
188
# File 'lib/lotus/model/mapping/coercions.rb', line 186

def self.Time(arg)
  Utils::Kernel.Time(arg) unless arg.nil?
end