Module: Kiba::Extend::Transforms::BooleanLambdaParamable
- Defined in:
- lib/kiba/extend/transforms/boolean_lambda_paramable.rb
Overview
Mixin module for transform classes that require a Lambda parameter that must return TrueClass or FalseClass
Testing
This mixin’s funtionality is tested in Marc::FilterRecords::WithLambda and FilterRows::WithLambda. It is not imperative to test in in every additional transform class where it may be used.
Usage
In class definition:
include BooleanLambdaParamable
Any transform classes mixing in this module must have a @lambda
instance variable on which is also set an attr_reader (private
or public is ok)
Add the following line to the top of the process
method if your lamba
takes a single argument:
test_lambda(row) unless lambda_tested
If your lambda takes multiple arguments, pass them in an Array in the
test_lambda
call:
test_lambda([val, row]) unless lambda_tested
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(mod) ⇒ Object
44 45 46 |
# File 'lib/kiba/extend/transforms/boolean_lambda_paramable.rb', line 44 def self.included(mod) mod.instance_variable_set(:@lambda_tested, false) end |
Instance Method Details
#lambda_tested ⇒ Object
48 |
# File 'lib/kiba/extend/transforms/boolean_lambda_paramable.rb', line 48 def lambda_tested = @lambda_tested |
#test_lambda(args) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/kiba/extend/transforms/boolean_lambda_paramable.rb', line 50 def test_lambda(args) result = args.is_a?(Array) ? lambda.call(*args) : lambda.call(args) unless result.is_a?(TrueClass) || result.is_a?(FalseClass) fail(Kiba::Extend::BooleanReturningLambdaError) end @lambda_tested = true end |