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


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

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


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

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


29
30
# File 'lib/hanami/model/mapping.rb', line 29

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


45
46
47
# File 'lib/hanami/model/mapping.rb', line 45

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


33
34
# File 'lib/hanami/model/mapping.rb', line 33

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


50
51
52
# File 'lib/hanami/model/mapping.rb', line 50

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


24
25
26
# File 'lib/hanami/model/mapping.rb', line 24

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


55
56
57
# File 'lib/hanami/model/mapping.rb', line 55

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