Class: Pipeable::Steps::Check

Inherits:
Abstract
  • Object
show all
Defined in:
lib/pipeable/steps/check.rb

Overview

Checks if proof is true and answers success (passthrough) or failure (with optional argument).

Instance Method Summary collapse

Methods included from Composable

#<<, #>>

Constructor Details

#initialize(proof, message) ⇒ Check

Returns a new instance of Check.



9
10
11
12
13
# File 'lib/pipeable/steps/check.rb', line 9

def initialize proof, message
  super()
  @proof = proof
  @message = message
end

Instance Method Details

#call(result) ⇒ Object



15
16
17
18
19
20
# File 'lib/pipeable/steps/check.rb', line 15

def call result
  result.bind do |object|
    answer = question object
    answer == true || answer.is_a?(Success) ? result : Failure(object)
  end
end