Class: BundledGem::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/bundled_gem/cli.rb

Overview

bundled_gem CLI class powered by thor

Instance Method Summary collapse

Instance Method Details

#install(*bundled_gems) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bundled_gem/cli.rb', line 11

def install(*bundled_gems)
  abort "Please specify at least one gem name (e.g. gem build GEMNAME)" if bundled_gems.empty?

  reader = LockfileReader.new(lockfile: options[:lockfile])
  bundled_gems.each do |bundled_gem|
    if reader.gem_listed?(bundled_gem)
      version = reader.get_version(bundled_gem)
      command = "gem install #{bundled_gem}:#{version}"
      IO.popen(command) do |f|
        while line = f.gets
          puts line
        end
      end
    else
      warn "`#{bundled_gem}` is not listed in Gemfile.lock."
    end
  end
end

#listObject



34
35
36
37
38
39
# File 'lib/bundled_gem/cli.rb', line 34

def list
  puts "Gems included in `#{options[:lockfile]}`:"
  LockfileReader.new(lockfile: options[:lockfile]).lockfile_specs.each do |spec|
    puts "  * #{spec.name}, #{spec.version}"
  end
end

#versionObject



42
43
44
# File 'lib/bundled_gem/cli.rb', line 42

def version
  puts ::BundledGem::VERSION
end