Class: Hanami::Model::Mapping Private

Inherits:
Object
  • Object
show all
Extended by:
Transproc::Registry
Defined in:
lib/hanami/model/mapping.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

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initialize(&blk) ⇒ Mapping

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 a new instance of Mapping.

Since:

  • 0.1.0



18
19
20
21
22
23
# File 'lib/hanami/model/mapping.rb', line 18

def initialize(&blk)
  @attributes   = {}
  @r_attributes = {}
  instance_eval(&blk)
  @processor = @attributes.empty? ? ::Hash : t(:rename_keys, @attributes)
end

Instance Method Details

#attribute(name, options) ⇒ 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.1.0



39
40
41
42
43
44
# File 'lib/hanami/model/mapping.rb', line 39

def attribute(name, options)
  from = options.fetch(:from, name)

  @attributes[name]   = from
  @r_attributes[from] = name
end

#model(entity) ⇒ 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.1.0



31
32
# File 'lib/hanami/model/mapping.rb', line 31

def model(entity)
end

#process(input) ⇒ 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.1.0



47
48
49
# File 'lib/hanami/model/mapping.rb', line 47

def process(input)
  @processor[input]
end

#register_as(name) ⇒ 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.1.0



35
36
# File 'lib/hanami/model/mapping.rb', line 35

def register_as(name)
end

#reverse?Boolean

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:

  • (Boolean)

Since:

  • 0.1.0



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

def reverse?
  @r_attributes.any?
end

#t(name, *args) ⇒ 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.1.0



26
27
28
# File 'lib/hanami/model/mapping.rb', line 26

def t(name, *args)
  self.class[name, *args]
end

#translate(attribute) ⇒ 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.1.0



57
58
59
# File 'lib/hanami/model/mapping.rb', line 57

def translate(attribute)
  @r_attributes.fetch(attribute)
end