Class: CuteKV::Validations::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/cute_kv/validations.rb

Instance Method Summary collapse

Constructor Details

#initializeError

Returns a new instance of Error.



13
14
15
# File 'lib/cute_kv/validations.rb', line 13

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

Instance Method Details

#add(attr, mesg) ⇒ Object



17
18
19
20
# File 'lib/cute_kv/validations.rb', line 17

def add(attr, mesg)
  attr = attr.to_s
  @body[attr] << mesg unless @body[attr].include?(mesg)
end

#empty?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/cute_kv/validations.rb', line 27

def empty?
  @body.values.flatten.empty?
end

#on(attr) ⇒ Object



22
23
24
25
# File 'lib/cute_kv/validations.rb', line 22

def on(attr)
  attr = attr.to_s
  @body[attr].size == 1 ? @body[attr].first : @body[attr]
end