Module: Dry::Schema

Extended by:
Core::Extensions
Includes:
Core::Constants
Defined in:
lib/dry/schema.rb,
lib/dry/schema/dsl.rb,
lib/dry/schema/key.rb,
lib/dry/schema/json.rb,
lib/dry/schema/path.rb,
lib/dry/schema/trace.rb,
lib/dry/schema/types.rb,
lib/dry/schema/config.rb,
lib/dry/schema/params.rb,
lib/dry/schema/result.rb,
lib/dry/schema/key_map.rb,
lib/dry/schema/message.rb,
lib/dry/schema/version.rb,
lib/dry/schema/compiler.rb,
lib/dry/schema/messages.rb,
lib/dry/schema/constants.rb,
lib/dry/schema/predicate.rb,
lib/dry/schema/processor.rb,
lib/dry/schema/macros/dsl.rb,
lib/dry/schema/macros/key.rb,
lib/dry/schema/key_coercer.rb,
lib/dry/schema/macros/core.rb,
lib/dry/schema/macros/each.rb,
lib/dry/schema/macros/hash.rb,
lib/dry/schema/message_set.rb,
lib/dry/schema/macros/array.rb,
lib/dry/schema/macros/maybe.rb,
lib/dry/schema/macros/value.rb,
lib/dry/schema/rule_applier.rb,
lib/dry/schema/macros/filled.rb,
lib/dry/schema/macros/schema.rb,
lib/dry/schema/messages/i18n.rb,
lib/dry/schema/messages/yaml.rb,
lib/dry/schema/type_registry.rb,
lib/dry/schema/value_coercer.rb,
lib/dry/schema/macros/optional.rb,
lib/dry/schema/macros/required.rb,
lib/dry/schema/namespaced_rule.rb,
lib/dry/schema/extensions/hints.rb,
lib/dry/schema/message_compiler.rb,
lib/dry/schema/extensions/monads.rb,
lib/dry/schema/messages/abstract.rb,
lib/dry/schema/messages/template.rb,
lib/dry/schema/predicate_inferrer.rb,
lib/dry/schema/predicate_registry.rb,
lib/dry/schema/messages/namespaced.rb,
lib/dry/schema/message_compiler/visitor_opts.rb,
lib/dry/schema/extensions/hints/result_methods.rb,
lib/dry/schema/extensions/hints/message_set_methods.rb,
lib/dry/schema/extensions/hints/message_compiler_methods.rb

Defined Under Namespace

Modules: Extensions, Macros, Messages, Types Classes: Compiler, Config, DSL, Hint, JSON, Key, KeyCoercer, KeyMap, Message, MessageCompiler, MessageSet, NamespacedRule, Params, Path, Predicate, PredicateInferrer, PredicateRegistry, Processor, Result, RuleApplier, Trace, TypeRegistry, ValueCoercer

Constant Summary collapse

VERSION =
'0.4.0'
LIST_SEPARATOR =
', '
QUESTION_MARK =
'?'
DOT =
'.'
DEFAULT_MESSAGES_PATH =
Pathname(__dir__).join('../../../config/errors.yml').realpath.freeze
DEFAULT_MESSAGES_ROOT =
'dry_schema'
InvalidSchemaError =
Class.new(StandardError)
MissingMessageError =
Class.new(StandardError) do
  # @api private
  def initialize(path)
    *rest, rule = path
    super(<<~STR)
      Message template for #{rule.inspect} under #{rest.join(DOT).inspect} was not found
    STR
  end
end

Class Method Summary collapse

Class Method Details

.define(**options, &block) ⇒ Processor

Define a schema

Returns:



19
20
21
# File 'lib/dry/schema.rb', line 19

def self.define(**options, &block)
  DSL.new(options, &block).call
end

.JSON(**options, &block) ⇒ JSON

Define a JSON schema

Returns:



38
39
40
# File 'lib/dry/schema.rb', line 38

def self.JSON(**options, &block)
  define(**options, processor_type: JSON, &block)
end

.Params(**options, &block) ⇒ Params

Define a param schema

Returns:



28
29
30
# File 'lib/dry/schema.rb', line 28

def self.Params(**options, &block)
  define(**options, processor_type: Params, &block)
end