Module: FlexValidations::Validation Abstract

Included in:
And, Call, Chain, Decorate, Or, Predicate
Defined in:
lib/flex_validations/validation.rb

Overview

This module is abstract.

Validation should define #validate and #to_s methods

Instance Method Summary collapse

Instance Method Details

#===(value) ⇒ Boolean

Examples:

case 1
when odd
  puts "its odd number"
end

Parameters:

  • Value (Object)

    to match

Returns:

  • (Boolean)


37
38
39
# File 'lib/flex_validations/validation.rb', line 37

def ===(value)
  validate(value).success? || super
end

#to_procProc

Examples:

[1, 2, 3].select(&odd) #=> [1, 3]

Returns:

  • (Proc)


45
46
47
# File 'lib/flex_validations/validation.rb', line 45

def to_proc
  proc { |value| validate(value).success? }
end

#to_sString

This method is abstract.

Returns description of validation

Returns:

  • (String)


24
25
26
# File 'lib/flex_validations/validation.rb', line 24

def to_s
  raise 'not implemented'
end

#validate(value) ⇒ FlexValidations::Result

This method is abstract.

Do validation of value

Examples:

odd.validate(1).success? #=> true
odd.validate(2).fail? #=> true

Parameters:

  • value (Object)

    Value to be validated

Returns:



17
18
19
# File 'lib/flex_validations/validation.rb', line 17

def validate(value)
  raise 'not implemented'
end