Class: Pah::Templates::Gem

Inherits:
Pah::Template
  • Object
show all
Defined in:
lib/pah/templates/gems.rb

Instance Method Summary collapse

Methods inherited from Pah::Template

#ask_unless_test, #copy_static_file, #git_commit, #static_files, #will_you_like_to?

Instance Method Details

#bundle_install_with_progressObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pah/templates/gems.rb', line 32

def bundle_install_with_progress
  require 'open3'
  output = ""
  status = 0
  Open3.popen3(ENV, "bundle install --jobs=4") do |stdin, stdout, stderr, wait_thr|
    while line = stdout.gets
      output += line
      print ".".green
    end
    status = wait_thr.value.to_i
  end
  puts ""
  [status, output]
end

#callObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pah/templates/gems.rb', line 4

def call
  copy_static_file 'Gemfile'

  gsub_file 'Gemfile', /RUBY_VERSION/, ::Pah::RUBY_VERSION
  gsub_file 'Gemfile', /RAILS_VERSION/, ::Pah::RAILS_VERSION

  begin
    require 'bundler'
  rescue LoadError
    # Install bundler if needed
    unless run 'gem install bundler --no-ri --no-rdoc'
      puts 'Error installing bundler, will attempt to continue'.red
    end
    require 'bundler'
  end

  # Install all other gems needed from Gemfile
  status, output = bundle_install_with_progress
  if status != 0
    puts output
    puts 'Error installing gems, aborting'.red
    exit 1
  end

  git add: 'Gemfile*'
  git_commit 'Add Gemfile and Gemfile.lock.'
end