Class: Veto::Errors

Inherits:
Hash
  • Object
show all
Defined in:
lib/veto/errors.rb

Instance Method Summary collapse

Instance Method Details

#add(atr, msg, *msg_opts) ⇒ Object



3
4
5
# File 'lib/veto/errors.rb', line 3

def add atr, msg, *msg_opts
	fetch(atr){self[atr] = []} << msg_lookup(msg, *msg_opts)
end

#countObject



7
8
9
# File 'lib/veto/errors.rb', line 7

def count
	values.inject(0){|m, v| m + v.length}
end

#empty?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/veto/errors.rb', line 11

def empty?
	count == 0
end

#full_messagesObject



15
16
17
18
19
20
21
# File 'lib/veto/errors.rb', line 15

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

#on(atr) ⇒ Object



23
24
25
26
27
# File 'lib/veto/errors.rb', line 23

def on(atr)
	if v = fetch(atr, nil) and !v.empty?
		v
	end
end