Class: Veto::Configuration::Message

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

Constant Summary collapse

DEFAULT_MESSAGES =
{
  :default                  => lambda {"is not valid"},
  :exact_length             => lambda {|exact| "is not #{exact} characters"},
  :format                   => lambda {"is not valid"},
  :greater_than             => lambda {|boundary| "must be greater than #{boundary}"},
  :greater_than_or_equal_to => lambda {|boundary| "must be greater than or equal to #{boundary}"},
  :inclusion                => lambda {|set| "is not in set: #{set.inspect}"},
  :integer                  => lambda {"is not a number"},
  :length_range             => lambda {"is too short or too long"},
  :less_than                => lambda {|boundary| "must be less than #{boundary}"},
  :less_than_or_equal_to    => lambda {|boundary| "must be less than or equal to #{boundary}"},
  :max_length               => lambda {|max| "is longer than #{max} characters"},
  :min_length               => lambda {|min| "is shorter than #{min} characters"},
  :not_null                 => lambda {"is not present"},
  :numeric                  => lambda {"is not a number"},
  :presence                 => lambda {"is not present"}
}

Instance Method Summary collapse

Constructor Details

#initializeMessage

Returns a new instance of Message.



22
23
24
# File 'lib/veto/configuration.rb', line 22

def initialize
  @messages = {}
end

Instance Method Details

#get(type, *args) ⇒ Object



26
27
28
# File 'lib/veto/configuration.rb', line 26

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

#set(type, proc) ⇒ Object



30
31
32
# File 'lib/veto/configuration.rb', line 30

def set(type, proc)
  @messages[type] = proc
end