Class: BundledGem::LockfileReader

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

Instance Method Summary collapse

Constructor Details

#initialize(lockfile: LOCKFILE) ⇒ LockfileReader

Returns a new instance of LockfileReader.



11
12
13
14
# File 'lib/bundled_gems.rb', line 11

def initialize(lockfile: LOCKFILE)
  abort "No such file: #{lockfile}" unless File.exist?(lockfile)
  @lockfile_content = File.read(lockfile)
end

Instance Method Details

#gem_listed?(gem) ⇒ Boolean

Check gem is listed in ‘Gemfile.lock`

Returns:

  • (Boolean)


27
28
29
# File 'lib/bundled_gems.rb', line 27

def gem_listed?(gem)
  lockfile_specs.map(&:name).include? gem
end

#get_version(gem) ⇒ Object

Get version info from ‘Gemfile.lock`



22
23
24
# File 'lib/bundled_gems.rb', line 22

def get_version(gem)
  lockfile_specs.find { |s| s.name == gem }&.version
end

#lockfile_specsObject

Parse ‘Gemfile.lock` and Retrieve specs



17
18
19
# File 'lib/bundled_gems.rb', line 17

def lockfile_specs
  lockfile.specs
end