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

Version Path
appfuel-0.7.0 lib/appfuel/validation/validator_pipe.rb
appfuel-0.6.16 lib/appfuel/validation/validator_pipe.rb
appfuel-0.6.15 lib/appfuel/validation/validator_pipe.rb
appfuel-0.6.14 lib/appfuel/validation/validator_pipe.rb
appfuel-0.6.13 lib/appfuel/validation/validator_pipe.rb
appfuel-0.6.12 lib/appfuel/validation/validator_pipe.rb
appfuel-0.6.11 lib/appfuel/validation/validator_pipe.rb
appfuel-0.6.10 lib/appfuel/validation/validator_pipe.rb
appfuel-0.6.9 lib/appfuel/validation/validator_pipe.rb
appfuel-0.6.8 lib/appfuel/validation/validator_pipe.rb
appfuel-0.6.7 lib/appfuel/validation/validator_pipe.rb
appfuel-0.6.6 lib/appfuel/validation/validator_pipe.rb
appfuel-0.6.5 lib/appfuel/validation/validator_pipe.rb
appfuel-0.6.4 lib/appfuel/validation/validator_pipe.rb
appfuel-0.6.3 lib/appfuel/validation/validator_pipe.rb
appfuel-0.6.1 lib/appfuel/validation/validator_pipe.rb
appfuel-0.5.16 lib/appfuel/validation/validator_pipe.rb
appfuel-0.5.15 lib/appfuel/validation/validator_pipe.rb
appfuel-0.5.14 lib/appfuel/validation/validator_pipe.rb
appfuel-0.5.13 lib/appfuel/validation/validator_pipe.rb