Class: Maven::Tools::GemfileLock

Inherits:
Hash
  • Object
show all
Defined in:
lib/maven/tools/gemfile_lock.rb

Defined Under Namespace

Classes: Dependency

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ GemfileLock

Returns a new instance of GemfileLock.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/maven/tools/gemfile_lock.rb', line 38

def initialize(file)
  super()
  current = nil
  bundler = false
  f = file.is_a?(File) ? file.path: file
  if File.exists? f
    File.readlines(f).each do |line|
      if line =~ /^BUNDLED WITH/
        bundler = true
      elsif bundler
        line.strip!
        current = Dependency.new("bundler (#{line})")
        self[current.name] = current
      elsif line =~ /^    [^ ]/
        line.strip!
        current = Dependency.new(line)
        self[current.name] = current
      elsif line =~ /^      [^ ]/
        line.strip!
        current.add(line) if current
      end
    end
  end
end

Instance Method Details

#dependency_hull(deps = []) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/maven/tools/gemfile_lock.rb', line 77

def dependency_hull(deps = [])
  deps = deps.is_a?(Array) ? deps : [deps]
  result = {}
  deps.each do |dep|
    recurse(result, dep)
  end
  result
end

#hullObject



86
87
88
# File 'lib/maven/tools/gemfile_lock.rb', line 86

def hull
  dependency_hull(keys)
end

#recurse(result, dep) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/maven/tools/gemfile_lock.rb', line 63

def recurse(result, dep)
  if d = self[dep]
    result[dep] = d.version if  !result.key?(dep)
    d.dependencies.each do |name, version|
      unless result.key? name
        if name != 'bundler'
          result[name] = self[name].nil?? version : self[name].version
          recurse(result, name)
        end
      end
    end
  end
end