Class: Spinup::Playground
- Inherits:
-
Object
- Object
- Spinup::Playground
- Defined in:
- lib/spinup/playground.rb
Class Method Summary collapse
Instance Method Summary collapse
- #copy_contents(where) ⇒ Object
- #establish(where) ⇒ Object
- #image_path ⇒ Object
-
#initialize(name, config) ⇒ Playground
constructor
A new instance of Playground.
- #run_commands(where) ⇒ Object
Constructor Details
#initialize(name, config) ⇒ Playground
Returns a new instance of Playground.
23 24 25 26 27 28 |
# File 'lib/spinup/playground.rb', line 23 def initialize(name, config) @name = name @copy = config[:copy_contents] @commands = config[:commands] end |
Class Method Details
.cd(where) ⇒ Object
7 8 9 |
# File 'lib/spinup/playground.rb', line 7 def cd(where) Dir.chdir(where) end |
.cp_r(from, where) ⇒ Object
11 12 13 14 |
# File 'lib/spinup/playground.rb', line 11 def cp_r(from, where) FileUtils.mkdir_p where FileUtils.cp_r(from, where) end |
.with_empty_lines_around ⇒ Object
16 17 18 19 20 |
# File 'lib/spinup/playground.rb', line 16 def with_empty_lines_around puts yield puts end |
Instance Method Details
#copy_contents(where) ⇒ Object
40 41 42 43 44 |
# 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) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# 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 ⇒ Object
46 47 48 |
# File 'lib/spinup/playground.rb', line 46 def image_path File.join(__dir__, "../../images/#{@name}/.") end |
#run_commands(where) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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 |