Class: PoroValidator::Configuration::Message

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

Overview

Since:

  • 0.0.1

Constant Summary collapse

DEFAULT_MESSAGES =

Since:

  • 0.0.1

{
  default:  lambda { "is not valid" },
  presence: lambda { "is not present" },
  integer:  lambda { "is not an integer" },
  float:    lambda { "is not a float" },

  integer_or_float: lambda do
    "is not an integer or float type"
  end,

  inclusion: lambda do |range|
    "is not within the range of #{range.inspect}"
  end,

  exclusion: lambda do |range|
    "is not outside the range of #{range.inspect}"
  end,

  format: lambda do |pattern|
    "does not match the pattern: #{pattern.inspect}"
  end,

  length: lambda do |length|
    "does not match the length options: #{length.inspect}"
  end,

  numeric: lambda do |numeric|
    "does not match the numeric options: #{numeric.inspect}"
  end
}

Instance Method Summary collapse

Constructor Details

#initializeMessage

Returns a new instance of Message.

Since:

  • 0.0.1



36
37
38
# File 'lib/poro_validator/configuration.rb', line 36

def initialize
  @messages = {}
end

Instance Method Details

#get(validator, *args) ⇒ Object

Since:

  • 0.0.1



40
41
42
# File 'lib/poro_validator/configuration.rb', line 40

def get(validator, *args)
  args.compact.length > 0 ? message(validator).call(*args) : message(validator).call
end

#set(validator, message) ⇒ Object

Since:

  • 0.0.1



44
45
46
47
48
49
50
51
# File 'lib/poro_validator/configuration.rb', line 44

def set(validator, message)
  unless message.is_a?(::Proc)
    raise PoroValidator::ConfigError.new(
      "A proc/lambda is required to configure validator messages"
    )
  end
  @messages[validator] = message
end