Class: Schemacop::V3::NodeRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/schemacop/v3/node_registry.rb

Class Method Summary collapse

Class Method Details

.by_name(name) ⇒ Object



32
33
34
# File 'lib/schemacop/v3/node_registry.rb', line 32

def self.by_name(name)
  @by_name[name.to_sym]
end

.by_short_name(short_name) ⇒ Object



36
37
38
# File 'lib/schemacop/v3/node_registry.rb', line 36

def self.by_short_name(short_name)
  @by_short_name[short_name.to_sym]
end

.dsl_methods(bang) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/schemacop/v3/node_registry.rb', line 14

def self.dsl_methods(bang)
  return @by_short_name.keys.map do |short_name|
    if bang
      ["dsl_#{short_name}!", "dsl_#{short_name}?"]
    else
      ["dsl_#{short_name}"]
    end
  end.flatten.map(&:to_sym)
end

.find(name_or_klass) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/schemacop/v3/node_registry.rb', line 24

def self.find(name_or_klass)
  if name_or_klass.is_a?(Class)
    return name_or_klass
  else
    return by_name(name_or_klass)
  end
end

.name(klass) ⇒ Object



40
41
42
# File 'lib/schemacop/v3/node_registry.rb', line 40

def self.name(klass)
  @by_class[klass][:name]
end

.register(name, short_name, klass) ⇒ Object



8
9
10
11
12
# File 'lib/schemacop/v3/node_registry.rb', line 8

def self.register(name, short_name, klass)
  @by_name[name.to_sym] = klass
  @by_short_name[short_name.to_sym] = klass
  @by_class[klass] = { name: name.to_sym, short_name: short_name.to_sym }
end