Class: Appfuel::Validation::ValidatorPipe

Inherits:
Object
  • Object
show all
Defined in:
lib/appfuel/validation/validator_pipe.rb

Overview

A pipe is just a lambda that take two arguments. It is designed to live between two validators in an array and maninuplate the output of the first validator to satisfy the secord. It is needed when you want to use two reusable validators that don’t quite work togather.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, dependencies = {}, &block) ⇒ ValidatorPipe



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/appfuel/validation/validator_pipe.rb', line 15

def initialize(name, dependencies = {}, &block)
  unless block_given?
    fail ArgumentError, "block is required"
  end

  unless block.arity == 2
    fail ArgumentError, "validator pipe block needs two params"
  end

  @name = name
  @code = block
  @dependencies = dependencies
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



9
10
11
# File 'lib/appfuel/validation/validator_pipe.rb', line 9

def code
  @code
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



9
10
11
# File 'lib/appfuel/validation/validator_pipe.rb', line 9

def dependencies
  @dependencies
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/appfuel/validation/validator_pipe.rb', line 9

def name
  @name
end

Instance Method Details

#call(inputs, data = Dry::Container.new) ⇒ Hash

Delegate call to the actual pipe lambda



42
43
44
# File 'lib/appfuel/validation/validator_pipe.rb', line 42

def call(inputs, data = Dry::Container.new)
  code.call(inputs, data)
end

#pipe?TrueCase

Because validator and pipe live togather in the same array. The system runner needs to be able to tell them apart.



33
34
35
# File 'lib/appfuel/validation/validator_pipe.rb', line 33

def pipe?
  true
end