Module: OpenBEL::PluginRepository

Includes:
Enumerable
Included in:
PluginManager
Defined in:
lib/openbel/api/plugin/plugin_repository.rb

Constant Summary collapse

WRITE_MUTEX =
Mutex.new

Instance Method Summary collapse

Instance Method Details

#eachObject Also known as: each_plugin



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/openbel/api/plugin/plugin_repository.rb', line 25

def each
  WRITE_MUTEX.lock
  begin
    @paths ||= []
    if block_given?
      require_plugins(@paths)
      plugins.each { |p| yield p.new }
    else
      enum_for(:each)
    end
  ensure
    WRITE_MUTEX.unlock
  end
end

#find_plugins(id, type = nil) ⇒ Object



19
20
21
22
23
# File 'lib/openbel/api/plugin/plugin_repository.rb', line 19

def find_plugins(id, type = nil)
  find_all { |p|
    ([p.id, p.name].include? id) and (!type or p.type == type.to_s.to_sym)
  }
end

#with_plugins_from(*paths) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/openbel/api/plugin/plugin_repository.rb', line 9

def with_plugins_from(*paths)
  WRITE_MUTEX.lock
  begin
    (@paths ||= []).concat paths.flatten.compact.uniq
  ensure
    WRITE_MUTEX.unlock
  end
  self
end