class Pluginator::Autodetect::FormattedFinder
Categorize plugins @see: Finder
Public Class Methods
new(force_prefix, group, force_type)
click to toggle source
Reformat plugin lists
Calls superclass method
Pluginator::Autodetect::Finder::new
# File lib/pluginator/autodetect/formatted_finder.rb, line 30 def initialize(force_prefix, group, force_type) super map_loaded_plugins map_gem_plugins end
Private Instance Methods
active_or_latest_gemspec(specifications)
click to toggle source
find active or latest gem in given set
# File lib/pluginator/autodetect/formatted_finder.rb, line 94 def active_or_latest_gemspec(specifications) specifications.find(&:activated) || specifications.last end
calculate_plugin_version(metadata, path)
click to toggle source
# File lib/pluginator/autodetect/formatted_finder.rb, line 104 def calculate_plugin_version(metadata, path) ( (metadata || {})[path] || "0" ).to_i end
find_gem_specifications()
click to toggle source
# File lib/pluginator/autodetect/formatted_finder.rb, line 56 def find_gem_specifications if gem_has_method?(:gemdeps) && Gem.gemdeps then # :nocov: only testable with using rubygems's gemdeps feature Gem.loaded_specs.values.to_a # :nocov: else specs = Gem::Specification._all.to_a specs = (Gem.loaded_specs.values.to_a + specs).uniq if gem_has_method?(:loaded_specs) specs end end
find_latest_plugin_version(gemspecs, path)
click to toggle source
# File lib/pluginator/autodetect/formatted_finder.rb, line 89 def find_latest_plugin_version(gemspecs, path) active_or_latest_gemspec(gemspecs_sorted_by_metadata_and_version(gemspecs, path)) end
gem_has_method?(name)
click to toggle source
# File lib/pluginator/autodetect/formatted_finder.rb, line 38 def gem_has_method?(name) Gem.methods.map(&:to_sym).include?(name) end
gemspec_for_path(path, specifications)
click to toggle source
# File lib/pluginator/autodetect/formatted_finder.rb, line 70 def gemspec_for_path(path, specifications) gemspecs = gemspecs_for_path(path, specifications) case gemspecs.size when 0 nil when 1 gemspecs.first else find_latest_plugin_version(gemspecs, path) end end
gemspecs_for_path(path, specifications)
click to toggle source
# File lib/pluginator/autodetect/formatted_finder.rb, line 83 def gemspecs_for_path(path, specifications) specifications.reject do |spec| Dir.glob( File.join( spec.lib_dirs_glob, path ) ).empty? end end
gemspecs_sorted_by_metadata_and_version(gemspecs, path)
click to toggle source
# File lib/pluginator/autodetect/formatted_finder.rb, line 98 def gemspecs_sorted_by_metadata_and_version(gemspecs, path) gemspecs.sort_by do |spec| [calculate_plugin_version(spec.metadata, path), spec.name, spec.version] end end
map_gem_plugins()
click to toggle source
# File lib/pluginator/autodetect/formatted_finder.rb, line 48 def map_gem_plugins gem_specifications = find_gem_specifications @gem_plugins_paths.map! do |path, name, type| gemspec = gemspec_for_path(path, gem_specifications) [gemspec, path, name, type] if gemspec end.compact end
map_loaded_plugins()
click to toggle source
# File lib/pluginator/autodetect/formatted_finder.rb, line 42 def map_loaded_plugins @loaded_plugins_path.map! do |_path, name, type| [name, type] end end