Class: Ohm::ActiveModelInterface::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/ohm/contrib/active_model_extension.rb

Instance Method Summary collapse

Constructor Details

#initialize(scope, errors) ⇒ Errors

Returns a new instance of Errors.



63
64
65
66
67
68
69
70
# File 'lib/ohm/contrib/active_model_extension.rb', line 63

def initialize(scope, errors)
  @scope  = scope
  @errors = Hash.new { |hash, key| hash[key] = [] }

  errors.each do |key, value|
    @errors[key] << value
  end
end

Instance Method Details

#[](key) ⇒ Object



72
73
74
# File 'lib/ohm/contrib/active_model_extension.rb', line 72

def [](key)
  @errors[key]
end

#full_messagesObject



76
77
78
79
80
# File 'lib/ohm/contrib/active_model_extension.rb', line 76

def full_messages
  @errors.map do |key, value|
    I18n::t("ohm.%s.%s.%s" % [@scope, key, value])
  end
end