class Spinup::Playground

Public Class Methods

cd(where) click to toggle source
# File lib/spinup/playground.rb, line 7
def cd(where)
  Dir.chdir(where)
end
cp_r(from, where) click to toggle source
# File lib/spinup/playground.rb, line 11
def cp_r(from, where)
  FileUtils.mkdir_p where
  FileUtils.cp_r(from, where)
end
new(name, config) click to toggle source
# File lib/spinup/playground.rb, line 23
def initialize(name, config)
  @name = name

  @copy = config[:copy_contents]
  @commands = config[:commands]
end
with_empty_lines_around() { || ... } click to toggle source
# File lib/spinup/playground.rb, line 16
def with_empty_lines_around
  puts
  yield
  puts
end

Public Instance Methods

copy_contents(where) click to toggle source
# File lib/spinup/playground.rb, line 40
def copy_contents(where)
  self.class.cp_r(image_path, where)

  puts "New #{@name} playground created under #{where}"
end
establish(where) { || ... } click to toggle source
# File lib/spinup/playground.rb, line 30
def establish(where)
  puts "establishing playgound at #{where}"

  copy_contents(where) if @copy

  yield if block_given?

  run_commands(where)
end
image_path() click to toggle source
# File lib/spinup/playground.rb, line 46
def image_path
  File.join(__dir__, "../../images/#{@name}/.")
end
run_commands(where) click to toggle source
# File lib/spinup/playground.rb, line 50
def run_commands(where)
  @commands.each do |command|
    self.class.with_empty_lines_around do
      puts "=> running #{ColorizedString.new(command, :green)}"
    end

    # prevent using ./Gemfile when spawning ruby processes
    Bundler.with_unbundled_env do
      pid = Process.spawn(command, out: $stdout, err: $stderr, chdir: where)
      Process.wait(pid)
    end
  end
end