Class: Rails::Angulate::Mappers::BaseMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/angulate/mappers/base_mapper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, attribute, validator) ⇒ BaseMapper

Returns a new instance of BaseMapper.



13
14
15
16
17
# File 'lib/rails/angulate/mappers/base_mapper.rb', line 13

def initialize(model, attribute, validator)
  @model = model
  @attribute = attribute
  @validator = validator
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



5
6
7
# File 'lib/rails/angulate/mappers/base_mapper.rb', line 5

def attribute
  @attribute
end

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/rails/angulate/mappers/base_mapper.rb', line 5

def model
  @model
end

#validatorObject (readonly)

Returns the value of attribute validator.



5
6
7
# File 'lib/rails/angulate/mappers/base_mapper.rb', line 5

def validator
  @validator
end

Class Method Details

.inherited(mapper) ⇒ Object



7
8
9
# File 'lib/rails/angulate/mappers/base_mapper.rb', line 7

def self.inherited(mapper)
  Mappers.register_mapper(mapper)
end

Instance Method Details

#error_messagesObject



19
20
21
# File 'lib/rails/angulate/mappers/base_mapper.rb', line 19

def error_messages
  []
end

#full_message(message) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rails/angulate/mappers/base_mapper.rb', line 23

def full_message(message)
  return message if attribute == :base
  attr_name = attribute.to_s.tr('.', '_').humanize
  attr_name = @model.class.human_attribute_name(attribute, default: attribute.to_s.humanize)
  with_i18n do |locale|
    locale.t(:format, {
      default:  "%{attribute} %{message}",
      attribute: attr_name.to_s.humanize,
      message:   message
    })
  end
end