Class: Thug::GemDetector

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

Instance Method Summary collapse

Constructor Details

#initializeGemDetector

initialize gemfile path



5
6
7
8
# File 'lib/thug/gem_detector.rb', line 5

def initialize
	cwd = Dir.getwd
	@gemfile_path = cwd + "/Gemfile"
end

Instance Method Details

#has_gem?Boolean

check if gemfile exists in the current directory

Returns:

  • (Boolean)


11
12
13
# File 'lib/thug/gem_detector.rb', line 11

def has_gem?
	File.file?(@gemfile_path)
end

#list_gemsObject

lists gems in current project



23
24
25
26
27
28
29
30
31
32
# File 'lib/thug/gem_detector.rb', line 23

def list_gems
	self.update_lock

	@gemfile_path = File.expand_path(@gemfile_path)

	lockfile_path = "#{@gemfile_path}.lock"
	lockfile = Bundler::LockfileParser.new(Bundler.read_file(lockfile_path))

	lockfile.specs.map(&:name)
end

#update_lockObject

update the .lock file without installing gems



16
17
18
19
20
# File 'lib/thug/gem_detector.rb', line 16

def update_lock
	puts "updating gemfile.lock"
	`bundle lock`
	puts "updated"
end