module Linearly::Validation::Expectation

{Expectation} is a helper module to turn various types of expectations into {Proc}s.

Public Class Methods

to_proc(expectation) click to toggle source

Turn one of the supported expecation types into a Proc

This method reeks of :reek:TooManyStatements.

@param expectation [Symbol|Class|Proc]

@return [Proc] @api private

# File lib/linearly/validation.rb, line 187
def to_proc(expectation)
  klass = expectation.class
  return ->(value) { value.is_a?(expectation) } if klass == Class
  return ->(_) { true } if klass == TrueClass
  expectation
end

Private Instance Methods

to_proc(expectation) click to toggle source

Turn one of the supported expecation types into a Proc

This method reeks of :reek:TooManyStatements.

@param expectation [Symbol|Class|Proc]

@return [Proc] @api private

# File lib/linearly/validation.rb, line 187
def to_proc(expectation)
  klass = expectation.class
  return ->(value) { value.is_a?(expectation) } if klass == Class
  return ->(_) { true } if klass == TrueClass
  expectation
end