Class: PoroValidator::Errors

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

Overview

Since:

  • 0.0.1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeErrors

Returns a new instance of Errors.

Since:

  • 0.0.1



6
7
8
# File 'lib/poro_validator/errors.rb', line 6

def initialize
  @store = ErrorStore.new
end

Instance Attribute Details

#storeObject (readonly)

Since:

  • 0.0.1



4
5
6
# File 'lib/poro_validator/errors.rb', line 4

def store
  @store
end

Instance Method Details

#add(attr, validator, *msg_opts) ⇒ Object

Since:

  • 0.0.1



10
11
12
13
14
15
16
# File 'lib/poro_validator/errors.rb', line 10

def add(attr, validator, *msg_opts)
  if store.set?(attr)
    store.get(attr) << message_lookup(validator, *msg_opts)
  else
    store.set(attr, [message_lookup(validator, *msg_opts)])
  end
end

#clear_errorsObject

Since:

  • 0.0.1



42
43
44
# File 'lib/poro_validator/errors.rb', line 42

def clear_errors
  self.store.reset
end

#countObject

Since:

  • 0.0.1



18
19
20
21
22
23
# File 'lib/poro_validator/errors.rb', line 18

def count
  store.data.inject(0) do |m, kv|
    _, errors = *kv
    m + errors.length
  end
end

#empty?Boolean

Returns:

  • (Boolean)

Since:

  • 0.0.1



25
26
27
# File 'lib/poro_validator/errors.rb', line 25

def empty?
  count == 0
end

#full_messagesObject

Since:

  • 0.0.1



29
30
31
32
33
34
35
# File 'lib/poro_validator/errors.rb', line 29

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

#on(attr) ⇒ Object Also known as: []

Since:

  • 0.0.1



37
38
39
40
# File 'lib/poro_validator/errors.rb', line 37

def on(attr)
  return unless store.set?(attr)
  store.get(attr)
end