Class: Helene::Sdb::Base::Validations::Errors

Inherits:
Hash
  • Object
show all
Defined in:
lib/helene/sdb/base/validations.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#symbolize_keys

Constructor Details

#initialize(object = nil) ⇒ Errors

Returns a new instance of Errors.



56
57
58
59
60
# File 'lib/helene/sdb/base/validations.rb', line 56

def initialize object = nil
  @object = object
  block = lambda{|h,k| h[k] = []}
  super(&block)
end

Instance Attribute Details

#objectObject

Returns the value of attribute object.



51
52
53
# File 'lib/helene/sdb/base/validations.rb', line 51

def object
  @object
end

Class Method Details

._load(string) ⇒ Object



62
63
64
# File 'lib/helene/sdb/base/validations.rb', line 62

def Errors._load(string)
  new.update(Marshal.load(string))
end

Instance Method Details

#_dump(*a) ⇒ Object



66
67
68
# File 'lib/helene/sdb/base/validations.rb', line 66

def _dump(*a)
  Marshal.dump({}.update(to_hash))
end

#add(att, msg) ⇒ Object



78
79
80
# File 'lib/helene/sdb/base/validations.rb', line 78

def add(att, msg)
  self[att] << msg
end

#countObject



70
71
72
# File 'lib/helene/sdb/base/validations.rb', line 70

def count
  size
end

#full_messagesObject



82
83
84
85
86
87
# File 'lib/helene/sdb/base/validations.rb', line 82

def full_messages
  inject([]) do |m, kv| att, errors = *kv
    errors.each {|e| m << "#{att} #{e}"}
    m
  end
end

#messageObject



89
90
91
# File 'lib/helene/sdb/base/validations.rb', line 89

def message
  full_messages.join(' | ')
end

#on(att) ⇒ Object



74
75
76
# File 'lib/helene/sdb/base/validations.rb', line 74

def on(att)
  self[att]
end