class Guard::Internals::Plugins
Public Class Methods
new()
click to toggle source
# File lib/guard/internals/plugins.rb, line 9 def initialize @plugins = [] end
Public Instance Methods
add(name, options)
click to toggle source
TODO: should it allow duplicates? (probably yes because of different configs or groups)
# File lib/guard/internals/plugins.rb, line 25 def add(name, options) @plugins << PluginUtil.new(name).initialize_plugin(options) end
all(filter = nil)
click to toggle source
# File lib/guard/internals/plugins.rb, line 13 def all(filter = nil) return @plugins if filter.nil? matcher = matcher_for(filter) @plugins.select { |plugin| matcher.call(plugin) } end
remove(plugin)
click to toggle source
# File lib/guard/internals/plugins.rb, line 19 def remove(plugin) @plugins.delete(plugin) end
Private Instance Methods
matcher_for(filter)
click to toggle source
# File lib/guard/internals/plugins.rb, line 31 def matcher_for(filter) case filter when String, Symbol shortname = filter.to_s.downcase.delete("-") ->(plugin) { plugin.name == shortname } when Regexp ->(plugin) { plugin.name =~ filter } when Hash lambda do |plugin| filter.all? do |k, v| case k when :name plugin.name == v.to_s.downcase.delete("-") when :group plugin.group.name == v.to_sym end end end end end