Module: Polisher::GemfileParser::ClassMethods

Defined in:
lib/polisher/gemfile/parser.rb

Instance Method Summary collapse

Instance Method Details

#parse(path, args = {}) ⇒ Polisher::Gemfile

Parse the specified gemfile & return new Gemfile instance from metadata

Parameters:

  • path (String)

    to gemfile to parse

Returns:



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
# File 'lib/polisher/gemfile/parser.rb', line 17

def parse(path, args = {})
  require 'bundler'

  groups = args[:groups]

  definition = nil
  path, gemfile = File.split(path)
  Dir.chdir(path) do
    begin
      definition = Bundler::Definition.build(gemfile, nil, false)
    rescue Bundler::GemfileNotFound
      raise ArgumentError, "invalid gemfile: #{path}"
    end
  end

   = {}
  [:deps] = definition.dependencies.select do |d|
    groups.nil? || groups.empty? ||                  # groups not specified
    groups.any? { |g| d.groups.include?(g.intern) }  # dep in any group
  end

  [:dev_deps] = [] # TODO
  [:definition] = definition

  new 
end