Module: Vldt::Common

Extended by:
Common
Included in:
Common
Defined in:
lib/vldt/common.rb

Instance Method Summary collapse

Instance Method Details

#absentObject

Validate, that an object is nil.



28
29
30
# File 'lib/vldt/common.rb', line 28

def absent
  Predicate.new(:absent, &:nil?)
end

#chain(*validations) ⇒ Object



7
8
9
# File 'lib/vldt/common.rb', line 7

def chain (*validations)
  Vldt::Chain.new(*validations)
end

#each(*validations) ⇒ Object



23
24
25
# File 'lib/vldt/common.rb', line 23

def each (*validations)
  Vldt::Each.new(*validations)
end

#eqls(value) ⇒ Object

Validates that the object equals (eql?) a value.



43
44
45
# File 'lib/vldt/common.rb', line 43

def eqls (value)
  Predicate.new(:eqls, value: value) { |o| value.eql?(o) }
end

#equals(value) ⇒ Object

Validate the equality (==) of the object with a value.



38
39
40
# File 'lib/vldt/common.rb', line 38

def equals (value)
  Predicate.new(:equals, value: value) { |o| o == value }
end

#identical(value) ⇒ Object

Validates that object and value are identical (equal?).



48
49
50
# File 'lib/vldt/common.rb', line 48

def identical (value)
  Predicate.new(:identical, value: value) { |o| value.equal?(o) }
end

#is_a(klass) ⇒ Object

Validate, that an object is an instance of a class.



53
54
55
# File 'lib/vldt/common.rb', line 53

def is_a (klass)
  Predicate.new(:is_a, class: klass) { |o| o.is_a?(klass) }
end

#join(*validations) ⇒ Object



3
4
5
# File 'lib/vldt/common.rb', line 3

def join (*validations)
  Vldt::Join.new(*validations)
end

#none_of(*values) ⇒ Object

Validates that object is not included in a list of values.



63
64
65
# File 'lib/vldt/common.rb', line 63

def none_of (*values)
  Predicate.new(:none_of, values: values) { |o| values.none? { |v| v == o } }
end

#one_of(*values) ⇒ Object

Validates that object is included in a list of values.



58
59
60
# File 'lib/vldt/common.rb', line 58

def one_of (*values)
  Predicate.new(:one_of, values: values) { |o| values.any? { |v| v == o } }
end

#optional(validation) ⇒ Object



11
12
13
# File 'lib/vldt/common.rb', line 11

def optional (validation)
  Vldt::Optional.new(validation)
end

#presentObject

Validate, that an object is not nil.



33
34
35
# File 'lib/vldt/common.rb', line 33

def present
  Predicate.new(:present) { |o| !o.nil? }
end

#validate(key, validation) ⇒ Object



19
20
21
# File 'lib/vldt/common.rb', line 19

def validate (key, validation)
  Vldt::Validate.new(key, validation)
end

#with(block, validation) ⇒ Object



15
16
17
# File 'lib/vldt/common.rb', line 15

def with (block, validation)
  Vldt::With.new(block, validation)
end