Class: JsDuck::TagRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/jsduck/tag_registry.rb

Overview

Access to all @tag definitions.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(load_paths = []) ⇒ TagRegistry

Returns a new instance of TagRegistry.



36
37
38
39
40
41
42
43
# File 'lib/jsduck/tag_registry.rb', line 36

def initialize(load_paths=[])
  @patterns = {}
  @tagnames = {}
  @signatures = []
  @tags = []

  instantiate_tags(TagLoader.new(load_paths).load_all)
end

Instance Attribute Details

#signaturesObject (readonly)

Array of attributes to be shown in member signatures (and in order they should be shown in).



73
74
75
# File 'lib/jsduck/tag_registry.rb', line 73

def signatures
  @signatures
end

#tagsObject (readonly)

Array of all available tags



76
77
78
# File 'lib/jsduck/tag_registry.rb', line 76

def tags
  @tags
end

Class Method Details

.configure(opts) ⇒ Object

Configures TagRegistry according to the command line options.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jsduck/tag_registry.rb', line 14

def self.configure(opts)
  if opts.tags.length > 0
    # Reconfigures the registry with additional load paths.
    @instance = TagRegistry.new(opts.tags)
  else
    # Ensure the TagRegistry get instantiated just once.
    # Otherwise the parallel processing causes multiple requests
    # to initialize the TagRegistry, resulting in loading the Tag
    # definitions multiple times.
    instance
  end

  # The tooltip of @new can now be configured.
  get_by_name(:new).init_tooltip!(opts)
end

.instanceObject

Access to the singleton instance (only used internally)



8
9
10
11
# File 'lib/jsduck/tag_registry.rb', line 8

def self.instance
  @instance = TagRegistry.new unless @instance
  @instance
end

.method_missing(meth, *args, &block) ⇒ Object

Redirect calls from TagRegistry.method to TagRegistry.instance.method, making it behave like other Singleton classes.



32
33
34
# File 'lib/jsduck/tag_registry.rb', line 32

def self.method_missing(meth, *args, &block)
  self.instance.send(meth, *args, &block)
end

Instance Method Details

#get_by_name(name) ⇒ Object

Accesses tag by name - the symbol under which the tag data is stored in final hash.



89
90
91
# File 'lib/jsduck/tag_registry.rb', line 89

def get_by_name(name)
  @tagnames[name]
end

#get_by_pattern(name) ⇒ Object

Accesses tag by @name pattern



83
84
85
# File 'lib/jsduck/tag_registry.rb', line 83

def get_by_pattern(name)
  @patterns[name]
end

#instantiate_tags(tag_classes) ⇒ Object

Instantiates all descendants of JsDuck::Tag::Tag



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/jsduck/tag_registry.rb', line 46

def instantiate_tags(tag_classes)
  tag_classes.each do |cls|
    tag = cls.new()

    Array(tag.pattern).each do |pattern|
      @patterns[pattern] = tag
    end

    if tag.tagname
      @tagnames[tag.tagname] = tag
    end

    if tag.signature
      tag.signature[:tagname] = tag.tagname
      @signatures << tag.signature
    end

    @tags << tag
  end
end