Class: Lotus::Model::Mapping::Attribute Private

Inherits:
Object
  • Object
show all
Defined in:
lib/lotus/model/mapping/attribute.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Mapping attribute

Since:

  • 0.5.0

Constant Summary collapse

COERCERS_NAMESPACE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0

"Lotus::Model::Mapping::Coercers".freeze

Instance Method Summary collapse

Constructor Details

#initialize(name, coercer, options) ⇒ Lotus::Model::Mapping::Attribute

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a new attribute

Parameters:

  • name (#to_sym)

    attribute name

  • coercer (.load, .dump)

    a coercer

  • options (Hash)

    a set of options

Options Hash (options):

  • :as (#to_sym)

    Resolve mismatch between database column name and entity attribute name

See Also:

Since:

  • 0.5.0



32
33
34
35
36
# File 'lib/lotus/model/mapping/attribute.rb', line 32

def initialize(name, coercer, options)
  @name    = name.to_sym
  @coercer = coercer
  @options = options
end

Instance Method Details

#==(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0



64
65
66
67
68
69
# File 'lib/lotus/model/mapping/attribute.rb', line 64

def ==(other)
  self.class     == other.class   &&
    self.name    == other.name    &&
    self.mapped  == other.mapped  &&
    self.coercer == other.coercer
end

#dump_coercerObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0



58
59
60
# File 'lib/lotus/model/mapping/attribute.rb', line 58

def dump_coercer
  "#{ coercer }.dump"
end

#load_coercerObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0



52
53
54
# File 'lib/lotus/model/mapping/attribute.rb', line 52

def load_coercer
  "#{ coercer }.load"
end

#mappedSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the mapped name

Returns:

  • (Symbol)

    the mapped name

See Also:

Since:

  • 0.5.0



46
47
48
# File 'lib/lotus/model/mapping/attribute.rb', line 46

def mapped
  (@options.fetch(:as) { name }).to_sym
end