class Cbratest::GemfileScraper

Public Class Methods

new(root_path) click to toggle source
# File lib/cobratest/gemfile_scraper.rb, line 5
def initialize(root_path)
  @root_path = root_path
end

Public Instance Methods

name() click to toggle source
# File lib/cobratest/gemfile_scraper.rb, line 9
def name
  Pathname.new(@root_path).basename.to_s
end
to_s() click to toggle source
# File lib/cobratest/gemfile_scraper.rb, line 13
def to_s
  {name: name, options: {path: @root_path}}
end
transitive_cobra_dependencies() click to toggle source
# File lib/cobratest/gemfile_scraper.rb, line 17
def transitive_cobra_dependencies
  gem_dependencies.inject([]) do |memo, dep|
    if !!dep[:options][:path]
      absolute_dep = dep.clone
      absolute_dep[:options][:path] = File.expand_path(File.join(@root_path, dep[:options][:path]))
      memo << dep
    end
    memo
  end
end

Private Instance Methods

gem_dependencies() click to toggle source
# File lib/cobratest/gemfile_scraper.rb, line 30
def gem_dependencies
  gemfile_path = File.join(@root_path, "Gemfile")
  lockfile_path = File.join(@root_path, "Gemfile.lock")
  ::Bundler::Definition.build(gemfile_path, lockfile_path, nil).dependencies.inject([]) do |memo, dep|
    path = dep.source.path.to_s if dep.source && dep.source.path?
    if path == "."
      path = nil
    elsif path && !path.match(/#{dep.name}/)
      path = "#{path}/#{dep.name}"
    end
    memo << { name: dep.name, options: { path: path }}
    memo
  end
end