Sha256: e2c1149189e01b99215d2c3453bb31d599137cdd0f7ed4052769279427a85367
Contents?: true
Size: 940 Bytes
Versions: 3
Compression:
Stored size: 940 Bytes
Contents
module Natives class GemfileViewer def initialize(gemfile_path) @gemfile_path = gemfile_path end def gem_names extract_gem_names(bundle_list(@gemfile_path)) end protected def bundle_list(gemfile_path) # after trial-and-error, these steps work best: # 1. cd to dir containing the gemfile # 2. bundle list dir = File.expand_path(File.dirname(@gemfile_path)) filename = File.basename(@gemfile_path) output = %x{cd '#{dir}' && BUNDLE_GEMFILE=#{filename} bundle list 2>&1} successful_run = ($?.exitstatus == 0) unless successful_run raise "Cannot list gems in gemfile #{@gemfile_path.inspect}: #{output}" end output end def extract_gem_names(output) lines = output.split("\n") lines.shift # remove first line lines.map do |line| _, name, _ = line.split(" ") name end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
natives-0.5.2 | lib/natives/gemfile_viewer.rb |
natives-0.5.1 | lib/natives/gemfile_viewer.rb |
natives-0.5.0 | lib/natives/gemfile_viewer.rb |