Class: Schemacop::V2::NodeResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/schemacop/v2/node_resolver.rb

Class Method Summary collapse

Class Method Details

.register(node_class, before: nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/schemacop/v2/node_resolver.rb', line 6

def self.register(node_class, before: nil)
  if before
    unless (index = node_classes.find_index(before))
      fail "Cannot insert before class #{before} which has not been registered yet."
    end

    node_classes.insert(index, node_class)
  else
    self.node_classes += [node_class]
  end
end

.resolve(type) ⇒ Object



18
19
20
# File 'lib/schemacop/v2/node_resolver.rb', line 18

def self.resolve(type)
  node_classes.find { |c| c.type_matches?(type) }
end