Sha256: de1d56bfe6f671a70809875f917b88d2ce8cc48117f3b456e29f94cee4f47ddc

Contents?: true

Size: 1.13 KB

Versions: 20

Compression:

Stored size: 1.13 KB

Contents

module Foobara
  module Value
    class Validator < Processor
      class Runner < Processor::Runner
        runner_methods :validation_errors
      end

      class << self
        def foobara_manifest(to_include:)
          super.merge(processor_type: :transformer)
        end
      end

      # Should a Validator only return one type of error?
      def validation_errors(_value)
        # :nocov:
        raise "subclass responsibility"
        # :nocov:
      end

      def process_value(value)
        return Outcome.success(value) unless applicable?(value)

        errors = Util.array(validation_errors(value))

        if errors.empty?
          Outcome.success(value)
        else
          Outcome.new(errors:, result: value)
        end
      end

      def build_error(
        value = nil,
        message: error_message(value),
        context: error_context(value),
        path: error_path,
        **
      )
        error_class.new(
          path:,
          message:,
          context:,
          **
        )
      end

      def possible_errors
        [PossibleError.new(error_class, processor: self)]
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
foobara-0.0.20 projects/value/src/validator.rb
foobara-0.0.19 projects/value/src/validator.rb
foobara-0.0.18 projects/value/src/validator.rb
foobara-0.0.17 projects/value/src/validator.rb
foobara-0.0.16 projects/value/src/validator.rb
foobara-0.0.15 projects/value/src/validator.rb
foobara-0.0.14 projects/value/src/validator.rb
foobara-0.0.13 projects/value/src/validator.rb
foobara-0.0.12 projects/value/src/validator.rb
foobara-0.0.11 projects/value/src/validator.rb
foobara-0.0.10 projects/value/src/validator.rb
foobara-0.0.9 projects/value/src/validator.rb
foobara-0.0.8 projects/value/src/validator.rb
foobara-0.0.7 projects/value/src/validator.rb
foobara-0.0.6 projects/value/src/validator.rb
foobara-0.0.5 projects/value/src/validator.rb
foobara-0.0.4 projects/value/src/validator.rb
foobara-0.0.3 projects/value/src/validator.rb
foobara-0.0.2 projects/value/src/validator.rb
foobara-0.0.1 projects/value/src/validator.rb