Module: Chemicalml::Convention::Base
- Included in:
- Compchem, Dictionary, Molecular, UnitDictionary, UnitTypeDictionary
- Defined in:
- lib/chemicalml/convention/base.rb
Overview
Mixin that gives a convention module its registry behavior:
- `qname` / `namespace_uri` (must be implemented by the host)
- `constraints` (lazy array)
- `register(SomeConstraintClass)`
- `validate(document)` -> [Violation, ...]
The framework never inspects which constraints a convention has;
it just walks whatever was registered. Adding a new rule = a new
constraint subclass + a register call.
Instance Method Summary collapse
- #constraint_count ⇒ Object
- #constraints ⇒ Object
- #namespace_uri ⇒ Object
- #qname ⇒ Object
- #register(constraint_class) ⇒ Object
- #reset_constraints! ⇒ Object
-
#validate(document) ⇒ Object
Single-pass validation via Convention::Coordinator.
- #validate_report(document) ⇒ Object
Instance Method Details
#constraint_count ⇒ Object
46 47 48 |
# File 'lib/chemicalml/convention/base.rb', line 46 def constraint_count constraints.length end |
#constraints ⇒ Object
24 25 26 |
# File 'lib/chemicalml/convention/base.rb', line 24 def constraints @constraints ||= [] end |
#namespace_uri ⇒ Object
20 21 22 |
# File 'lib/chemicalml/convention/base.rb', line 20 def namespace_uri raise NotImplementedError, "#{name} must define its namespace URI" end |
#qname ⇒ Object
16 17 18 |
# File 'lib/chemicalml/convention/base.rb', line 16 def qname raise NotImplementedError, "#{name} must define its QName" end |
#register(constraint_class) ⇒ Object
28 29 30 31 32 |
# File 'lib/chemicalml/convention/base.rb', line 28 def register(constraint_class) constraints << constraint_class unless constraints.include?(constraint_class) @coordinator = nil # invalidate cached coordinator self end |
#reset_constraints! ⇒ Object
50 51 52 53 |
# File 'lib/chemicalml/convention/base.rb', line 50 def reset_constraints! @constraints = [] @coordinator = nil end |
#validate(document) ⇒ Object
Single-pass validation via Convention::Coordinator. The
coordinator builds a role-dispatch table from the declared
applies_to on each constraint, walks the tree once, and
dispatches each node only to applicable constraints.
38 39 40 |
# File 'lib/chemicalml/convention/base.rb', line 38 def validate(document) coordinator.validate(document) end |
#validate_report(document) ⇒ Object
42 43 44 |
# File 'lib/chemicalml/convention/base.rb', line 42 def validate_report(document) ValidationReport.new(validate(document)) end |