Class: Chemicalml::Convention::Constraint
- Inherits:
-
Object
- Object
- Chemicalml::Convention::Constraint
- Defined in:
- lib/chemicalml/convention/constraint.rb
Overview
Abstract base class for a single constraint. Subclasses implement
check_node (one node at a time) or check (whole document).
A constraint subclass MAY declare applies_to — one or more
Cml::Role::* modules. When it does, the Coordinator only
invokes check_node for nodes matching that role. Without
applies_to, the constraint receives every node (legacy
behaviour). Declaring applies_to is the fast path: the
dispatch is O(node.ancestors) per node, not O(constraint_count).
Defined Under Namespace
Classes: DocumentConstraint, NodeConstraint
Class Attribute Summary collapse
-
.applies_to_roles ⇒ Object
readonly
Returns the Role module(s) this constraint applies to, or nil if it must run for every node.
-
.description ⇒ String
Human-readable description of the rule this constraint enforces.
Class Method Summary collapse
-
.applies_to(*roles) ⇒ Object
Declare one or more Role modules this constraint handles.
-
.default_severity ⇒ Symbol
Severity this constraint emits.
Instance Method Summary collapse
- #check(_document) ⇒ Object
-
#initialize ⇒ Constraint
constructor
A new instance of Constraint.
Constructor Details
#initialize ⇒ Constraint
Returns a new instance of Constraint.
50 51 52 |
# File 'lib/chemicalml/convention/constraint.rb', line 50 def initialize freeze end |
Class Attribute Details
.applies_to_roles ⇒ Object (readonly)
Returns the Role module(s) this constraint applies to, or nil if it must run for every node.
18 19 20 |
# File 'lib/chemicalml/convention/constraint.rb', line 18 def applies_to_roles @applies_to_roles end |
.description ⇒ String
Human-readable description of the rule this constraint
enforces. Subclasses MAY override. Falls back to the class
name. Used by chemicalml constraints and the auto-generated
constraint docs.
33 34 35 |
# File 'lib/chemicalml/convention/constraint.rb', line 33 def description @description || name.split('::').last end |
Class Method Details
.applies_to(*roles) ⇒ Object
Declare one or more Role modules this constraint handles. applies_to Chemicalml::Cml::Role::Atom applies_to Chemicalml::Cml::Role::Bond, Chemicalml::Cml::Role::AtomParity
23 24 25 |
# File 'lib/chemicalml/convention/constraint.rb', line 23 def applies_to(*roles) @applies_to_roles = roles.flatten.freeze end |
.default_severity ⇒ Symbol
Severity this constraint emits. Subclasses MAY override.
Default :error — warning subclasses override to :warning.
45 46 47 |
# File 'lib/chemicalml/convention/constraint.rb', line 45 def default_severity :error end |
Instance Method Details
#check(_document) ⇒ Object
54 55 56 57 |
# File 'lib/chemicalml/convention/constraint.rb', line 54 def check(_document) raise NotImplementedError, "#{self.class} must implement #check(document)" end |