Sha256: 07f5d41c704396db6110550b90489f4f16e89f679b82dc544f8e85c99d3b2354
Contents?: true
Size: 1.41 KB
Versions: 55
Compression:
Stored size: 1.41 KB
Contents
module Appfuel module Validation # 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. class ValidatorPipe attr_reader :name, :dependencies, :code # # @param name [String] key used for errors & containers # @param dependencies [Hash] for dependency injection # @return [ValidatorPipe] 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 # Because validator and pipe live togather in the same array. The # system runner needs to be able to tell them apart. # # @return [TrueCase] def pipe? true end # Delegate call to the actual pipe lambda # # @param inputs [Hash] # @param data [Dry::Container] dependency injection container # @return [Hash] new inputs for the next validator def call(inputs, data = Dry::Container.new) code.call(inputs, data) end end end end
Version data entries
55 entries across 55 versions & 1 rubygems