Class: Ree::Contracts::ValidValidator

Inherits:
BaseValidator show all
Defined in:
lib/ree/contracts/validators/valid_validator.rb

Instance Attribute Summary

Attributes inherited from BaseValidator

#contract

Instance Method Summary collapse

Methods inherited from BaseValidator

#initialize

Methods included from Truncatable

#truncate

Constructor Details

This class inherits a constructor from Ree::Contracts::BaseValidator

Instance Method Details

#call(value) ⇒ Object



5
6
7
# File 'lib/ree/contracts/validators/valid_validator.rb', line 5

def call(value)
  contract.valid? value
end

#message(value, name, lvl = 1) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/ree/contracts/validators/valid_validator.rb', line 18

def message(value, name, lvl = 1)
  if contract.respond_to?(:message)
    contract.message(value, name, lvl)
  else
    obj_name = contract.is_a?(Class) ? contract : contract.class
    op = contract.is_a?(Class) ? '.' : '#'
    "#{obj_name}#{op}valid? failed for #{truncate(value.inspect)}"
  end
end

#to_sObject



9
10
11
12
13
14
15
16
# File 'lib/ree/contracts/validators/valid_validator.rb', line 9

def to_s
  if contract.respond_to?(:to_s)
    contract.to_s
  else
    klass = contract.is_a?(Class) ? contract : contract.class
    klass.name
  end
end