Class: CassandraORM::Model::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/cassandra-orm/model/errors.rb

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Errors



10
11
12
13
# File 'lib/cassandra-orm/model/errors.rb', line 10

def initialize object
  @object = object
  @errors = Hash.new { |h, k| h[k] = {} }
end

Instance Method Details

#append(attr, key, options = {}) ⇒ Object



17
18
19
# File 'lib/cassandra-orm/model/errors.rb', line 17

def append attr, key, options = {}
  @errors[attr].merge! key => options
end

#full_messages(locale: :en) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cassandra-orm/model/errors.rb', line 21

def full_messages locale: :en
  @errors.map do |attr, errlist|
    errlist.map do |key, options|
      if attr.to_s =~ /\[(.+)\]/
        skey, name = $1, @object.class.name.underscore
        I18n.t key, options.merge(scope: [:cassandra, name, :errors, skey], locale: locale)
      else
        I18n.t key, options.merge(attr: attr, scope: [:cassandra, :errors], locale: locale)
      end
    end
  end.flatten
end