Class: Gemkeeper::LockfileParser

Inherits:
Object
  • Object
show all
Defined in:
lib/gemkeeper/lockfile_parser.rb

Constant Summary collapse

LOCKFILE_NAME =
"Gemfile.lock"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lockfile_path) ⇒ LockfileParser

Returns a new instance of LockfileParser.



25
26
27
# File 'lib/gemkeeper/lockfile_parser.rb', line 25

def initialize(lockfile_path)
  @lockfile_path = lockfile_path
end

Class Method Details

.find(start_dir = Dir.pwd) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/gemkeeper/lockfile_parser.rb', line 7

def self.find(start_dir = Dir.pwd)
  dir = File.expand_path(start_dir)
  loop do
    candidate = File.join(dir, LOCKFILE_NAME)
    return candidate if File.exist?(candidate)

    parent = File.dirname(dir)
    break if parent == dir

    dir = parent
  end
  nil
end

.parse(lockfile_path) ⇒ Object



21
22
23
# File 'lib/gemkeeper/lockfile_parser.rb', line 21

def self.parse(lockfile_path)
  new(lockfile_path).gem_versions
end

Instance Method Details

#gem_versionsObject



29
30
31
32
# File 'lib/gemkeeper/lockfile_parser.rb', line 29

def gem_versions
  content = File.read(@lockfile_path)
  extract_gem_section(content)
end