Sha256: 05396f2ec550a424193386f94fc9985a25c3c1d9aeb92ca60196dc51d314baa1

Contents?: true

Size: 1011 Bytes

Versions: 4

Compression:

Stored size: 1011 Bytes

Contents

require 'dry-equalizer'
require 'dry-configurable'
require 'dry-container'

require 'dry/validation/schema'
require 'dry/validation/schema/form'

module Dry
  module Validation
    MissingMessageError = Class.new(StandardError)

    def self.messages_paths
      Messages::Abstract.config.paths
    end

    def self.Schema(base = Schema, **options, &block)
      dsl_opts = {
        schema_class: Class.new(base.is_a?(Schema) ? base.class : base),
        parent: options[:parent]
      }

      dsl = Schema::Value.new(dsl_opts)
      dsl.instance_exec(&block)

      klass = dsl.schema_class

      klass.configure do |config|
        config.rules = config.rules + (options.fetch(:rules, []) + dsl.rules)
        config.checks = config.checks + dsl.checks
        config.path = dsl.path
      end

      if options[:build] == false
        klass
      else
        klass.new
      end
    end

    def self.Form(options = {}, &block)
      Validation.Schema(Schema::Form, options, &block)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-validation-0.7.3 lib/dry/validation.rb
dry-validation-0.7.2 lib/dry/validation.rb
dry-validation-0.7.1 lib/dry/validation.rb
dry-validation-0.7.0 lib/dry/validation.rb