Class: Dry::Validation::SchemaCompiler
- Inherits:
-
Logic::RuleCompiler
- Object
- Logic::RuleCompiler
- Dry::Validation::SchemaCompiler
- Defined in:
- lib/dry/validation/schema_compiler.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
-
#initialize(*args, options) ⇒ SchemaCompiler
constructor
A new instance of SchemaCompiler.
- #visit_guard(node) ⇒ Object
- #visit_predicate(node) ⇒ Object
- #visit_schema(klass) ⇒ Object
- #visit_type(type) ⇒ Object
Constructor Details
#initialize(*args, options) ⇒ SchemaCompiler
Returns a new instance of SchemaCompiler.
34 35 36 37 38 |
# File 'lib/dry/validation/schema_compiler.rb', line 34 def initialize(*args, ) super(*args) @options = @schema = predicates.schema end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
32 33 34 |
# File 'lib/dry/validation/schema_compiler.rb', line 32 def @options end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
32 33 34 |
# File 'lib/dry/validation/schema_compiler.rb', line 32 def schema @schema end |
Instance Method Details
#visit_guard(node) ⇒ Object
55 56 57 58 |
# File 'lib/dry/validation/schema_compiler.rb', line 55 def visit_guard(node) deps, other = node Guard.new(visit(other), deps) end |
#visit_predicate(node) ⇒ Object
40 41 42 |
# File 'lib/dry/validation/schema_compiler.rb', line 40 def visit_predicate(node) super.evaluate_args!(schema) end |
#visit_schema(klass) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dry/validation/schema_compiler.rb', line 44 def visit_schema(klass) opt_keys = klass.config..keys opt_vals = .values_at(*opt_keys).compact if opt_vals.empty? klass.new else klass.new(klass.config.rules, Hash[opt_keys.zip(opt_vals)]) end end |
#visit_type(type) ⇒ Object
60 61 62 |
# File 'lib/dry/validation/schema_compiler.rb', line 60 def visit_type(type) type.rule end |