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_custom(node) ⇒ Object
- #visit_guard(node) ⇒ Object
- #visit_predicate(node) ⇒ Object
- #visit_rule(node) ⇒ Object
- #visit_schema(klass) ⇒ Object
- #visit_type(type) ⇒ Object
Constructor Details
#initialize(*args, options) ⇒ SchemaCompiler
Returns a new instance of SchemaCompiler.
38 39 40 41 42 |
# File 'lib/dry/validation/schema_compiler.rb', line 38 def initialize(*args, ) super(*args) = @schema = predicates.schema end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
36 37 38 |
# File 'lib/dry/validation/schema_compiler.rb', line 36 def end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
36 37 38 |
# File 'lib/dry/validation/schema_compiler.rb', line 36 def schema @schema end |
Instance Method Details
#visit_custom(node) ⇒ Object
53 54 55 56 |
# File 'lib/dry/validation/schema_compiler.rb', line 53 def visit_custom(node) id, predicate = node Logic::Rule.new(predicate).with(id: id).bind(schema) end |
#visit_guard(node) ⇒ Object
69 70 71 72 |
# File 'lib/dry/validation/schema_compiler.rb', line 69 def visit_guard(node) deps, other = node Guard.new(visit(other), deps) end |
#visit_predicate(node) ⇒ Object
49 50 51 |
# File 'lib/dry/validation/schema_compiler.rb', line 49 def visit_predicate(node) super.eval_args(schema) end |
#visit_rule(node) ⇒ Object
44 45 46 47 |
# File 'lib/dry/validation/schema_compiler.rb', line 44 def visit_rule(node) id, other = node visit(other).with(id: id) end |
#visit_schema(klass) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dry/validation/schema_compiler.rb', line 58 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
74 75 76 |
# File 'lib/dry/validation/schema_compiler.rb', line 74 def visit_type(type) type.rule end |