Module: Legion::Tools::Registry

Defined in:
lib/legion/tools/registry.rb

Class Method Summary collapse

Class Method Details

.all_toolsObject



43
44
45
# File 'lib/legion/tools/registry.rb', line 43

def all_tools
  @mutex.synchronize { @always.dup + @deferred.dup }
end

.always_loaded_namesObject



54
55
56
# File 'lib/legion/tools/registry.rb', line 54

def always_loaded_names
  tools.map(&:tool_name)
end

.clearObject



70
71
72
73
74
75
# File 'lib/legion/tools/registry.rb', line 70

def clear
  @mutex.synchronize do
    @always.clear
    @deferred.clear
  end
end

.deferred_toolsObject



39
40
41
# File 'lib/legion/tools/registry.rb', line 39

def deferred_tools
  @mutex.synchronize { @deferred.dup }
end

.find(name) ⇒ Object



47
48
49
50
51
52
# File 'lib/legion/tools/registry.rb', line 47

def find(name)
  @mutex.synchronize do
    @always.find { |t| t.tool_name == name } ||
      @deferred.find { |t| t.tool_name == name }
  end
end

.for_extension(ext_name) ⇒ Object



58
59
60
# File 'lib/legion/tools/registry.rb', line 58

def for_extension(ext_name)
  all_tools.select { |t| t.respond_to?(:extension) && t.extension == ext_name }
end

.for_runner(runner_name) ⇒ Object



62
63
64
# File 'lib/legion/tools/registry.rb', line 62

def for_runner(runner_name)
  all_tools.select { |t| t.respond_to?(:runner) && t.runner == runner_name }
end

.register(tool_class) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/legion/tools/registry.rb', line 11

def register(tool_class)
  name = tool_class.tool_name
  is_deferred = tool_class.respond_to?(:deferred?) && tool_class.deferred?
  bucket = is_deferred ? :deferred : :always

  @mutex.synchronize do
    target = bucket == :deferred ? @deferred : @always
    other  = bucket == :deferred ? @always : @deferred

    if target.any? { |t| t.tool_name == name } || other.any? { |t| t.tool_name == name }
      if defined?(Legion::Logging)
        Legion::Logging.warn(
          "[Tools::Registry] duplicate registration rejected: #{name} " \
          "(attempted by #{tool_class.name || tool_class.inspect})"
        )
      end
      return false
    end

    target << tool_class
    true
  end
end

.tagged(tag) ⇒ Object



66
67
68
# File 'lib/legion/tools/registry.rb', line 66

def tagged(tag)
  all_tools.select { |t| t.respond_to?(:tags) && t.tags.include?(tag) }
end

.toolsObject



35
36
37
# File 'lib/legion/tools/registry.rb', line 35

def tools
  @mutex.synchronize { @always.dup }
end