class PoroValidator::Errors

Attributes

store[R]

Public Class Methods

new() click to toggle source
# File lib/poro_validator/errors.rb, line 6
def initialize
  @store = ErrorStore.new
end

Public Instance Methods

[](attr)
Alias for: on
add(attr, validator, *msg_opts) click to toggle source
# 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_errors() click to toggle source
# File lib/poro_validator/errors.rb, line 42
def clear_errors
  self.store.reset
end
count() click to toggle source
# 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?() click to toggle source
# File lib/poro_validator/errors.rb, line 25
def empty?
  count == 0
end
full_messages() click to toggle source
# 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) click to toggle source
# File lib/poro_validator/errors.rb, line 37
def on(attr)
  return unless store.set?(attr)
  store.get(attr)
end
Also aliased as: []

Private Instance Methods

message_lookup(validator, *msg_opts) click to toggle source
# File lib/poro_validator/errors.rb, line 50
def message_lookup(validator, *msg_opts)
  validator.is_a?(Symbol) ? ::PoroValidator.configuration.message.get(
    validator, *msg_opts
  ) : validator
end