Skip to content
This repository has been archived by the owner on May 29, 2018. It is now read-only.

Don't create new process #7

Open
sunnyrjuneja opened this issue Sep 3, 2014 · 0 comments
Open

Don't create new process #7

sunnyrjuneja opened this issue Sep 3, 2014 · 0 comments

Comments

@sunnyrjuneja
Copy link

Right now, script_deps creates a new process by running gem list. You can get the same results without creating a new process by running Gem::Specification which responds to #each, #map, and #all. The upside is that every member of the collection responds to #version so you don't have to parse the results of gem list. The downside is that you can have multiple versions and they appear in the collection for every installed version.

#srclib-ruby/lib/srclib-ruby/scan.rb#L116-133
def script_deps(script_code)
  # Get a list of all installed gems
  installed_gems = `gem list`.split(/\n/).map do |line|
    line.split.first.strip #TODO: Extract version number
  end

  deps = []
  script_code.scan(/require\W["'](.*)["']/) do |required|
    if installed_gems.include? required[0].strip
      deps << [
        required[0].strip,
        ">= 0" #TODO: Should use the currently installed version number
      ]
    end
  end

  return deps
end
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant