Class: YES::Constraints::Kind

Inherits:
NodeConstraint show all
Defined in:
lib/yes/constraints/kind.rb

Overview

Validate the kind of node. There are only three kinds of nodes: ‘scalar`, `map` and `seq`.

Instance Attribute Summary

Attributes inherited from NodeConstraint

#node

Attributes inherited from AbstractConstraint

#nodes, #spec, #tree

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NodeConstraint

#initialize, #tag, #value

Methods inherited from AbstractConstraint

#applicable?, inherited, #initialize, #match_delta, #recurse_valid?, #valid?

Constructor Details

This class inherits a constructor from YES::Constraints::NodeConstraint

Class Method Details

.applicable?(spec) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/yes/constraints/kind.rb', line 20

def self.applicable?(spec)
  spec['kind']
end

.checklist(spec, tree, nodes) ⇒ Array<Constraint>

Returns:

  • (Array<Constraint>)


12
13
14
15
16
17
# File 'lib/yes/constraints/kind.rb', line 12

def self.checklist(spec, tree, nodes)
  return [] unless applicable?(spec)
  nodes.map do |node|
    new(spec, tree, node)
  end
end

Instance Method Details

#validate(spec) ⇒ Object

Validate type.



26
27
28
# File 'lib/yes/constraints/kind.rb', line 26

def validate(spec)
  node.kind.to_s == spec['kind']
end