Class: Definition::Types::Lambda

Inherits:
Base
  • Object
show all
Includes:
Dsl
Defined in:
lib/definition/types/lambda.rb

Defined Under Namespace

Modules: Dsl

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods included from Dsl

#conform_with

Methods inherited from Base

#explain

Constructor Details

#initialize(name, &test_lambda) ⇒ Lambda

Returns a new instance of Lambda.



15
16
17
18
# File 'lib/definition/types/lambda.rb', line 15

def initialize(name, &test_lambda)
  self.test_lambda = test_lambda
  super(name)
end

Instance Method Details

#conform(value) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/definition/types/lambda.rb', line 20

def conform(value)
  lambda_result = instance_exec(value, &test_lambda)
  return lambda_result if lambda_result.is_a?(ConformResult)

  ConformResult.new(value, errors: [
                      ConformError.new(self, "Did not pass test for #{name}")
                    ])
end