Class: Danger::PluginFileResolver
- Inherits:
-
Object
- Object
- Danger::PluginFileResolver
- Defined in:
- lib/danger/plugin_support/plugin_file_resolver.rb
Instance Method Summary collapse
-
#initialize(references) ⇒ PluginFileResolver
constructor
Takes an array of files, gems or nothing, then resolves them into paths that should be sent into the documentation parser.
- #resolve_to_paths ⇒ Object
Constructor Details
#initialize(references) ⇒ PluginFileResolver
Takes an array of files, gems or nothing, then resolves them into paths that should be sent into the documentation parser
8 9 10 |
# File 'lib/danger/plugin_support/plugin_file_resolver.rb', line 8 def initialize(references) @refs = references end |
Instance Method Details
#resolve_to_paths ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/danger/plugin_support/plugin_file_resolver.rb', line 12 def resolve_to_paths # When given existing paths, map to absolute & existing paths if !@refs.nil? and @refs.select { |ref| File.file? ref }.any? @refs.select { |ref| File.file? ref }.map { |path| File.(path) } # When given a list of gems elsif @refs and @refs.kind_of? Array Bundler.with_clean_env do Dir.mktmpdir do |dir| gem_names = @refs deps = gem_names.map { |name| Bundler::Dependency.new(name, ">= 0") } # Use Gems from rubygems.org source = Bundler::SourceList.new source.add_rubygems_remote("https://rubygems.org") # Create a definition to bundle, make sure it always updates # and uses the latest version from the server bundler = Bundler::Definition.new(nil, deps, source, true) bundler.resolve_remotely! # Install the gems into a tmp dir = { path: dir } Bundler::Installer.install(Pathname.new(dir), bundler, ) # Get the name'd gems out of bundler, then pull out all their paths gems = gem_names.flat_map { |name| bundler.specs[name] } gems.flat_map { |gem| Dir.glob(File.join(gem.gem_dir, "lib/**/**/**.rb")) } end end # When empty, imply you want to test the current lib folder as a plugin else Dir.glob(File.join(".", "lib/*.rb")).map { |path| File.(path) } end end |