Class: PoroValidator::Configuration::Message
- Inherits:
-
Object
- Object
- PoroValidator::Configuration::Message
- Defined in:
- lib/poro_validator/configuration.rb
Overview
Constant Summary collapse
- DEFAULT_MESSAGES =
{ 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
- #get(validator, *args) ⇒ Object
-
#initialize ⇒ Message
constructor
A new instance of Message.
- #set(validator, message) ⇒ Object
Constructor Details
#initialize ⇒ Message
Returns a new instance of Message.
36 37 38 |
# File 'lib/poro_validator/configuration.rb', line 36 def initialize @messages = {} end |
Instance Method Details
#get(validator, *args) ⇒ Object
40 41 42 |
# File 'lib/poro_validator/configuration.rb', line 40 def get(validator, *args) args.compact.length > 0 ? (validator).call(*args) : (validator).call end |
#set(validator, message) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/poro_validator/configuration.rb', line 44 def set(validator, ) unless .is_a?(::Proc) raise PoroValidator::ConfigError.new( "A proc/lambda is required to configure validator messages" ) end @messages[validator] = end |