Module: Construct::Helpers

Extended by:
Helpers
Includes:
PathExtensions
Included in:
Construct, Helpers
Defined in:
lib/construct/helpers.rb

Instance Attribute Summary

Attributes included from PathExtensions

#construct__chdir_default

Instance Method Summary collapse

Methods included from PathExtensions

#chdir, #destroy!, #directory, #file, #maybe_change_dir

Instance Method Details

#create_construct(chdir = true) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/construct/helpers.rb', line 17

def create_construct(chdir=true)
  path = (Pathname(Construct.tmpdir) + 
    "#{CONTAINER_PREFIX}-#{$PROCESS_ID}-#{rand(1_000_000_000)}")
  path.mkpath
  path.extend(PathExtensions)
  path.construct__chdir_default = chdir
  path
end

#within_construct(chdir = true) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/construct/helpers.rb', line 8

def within_construct(chdir=true)
  container = create_construct(chdir)
  container.maybe_change_dir(chdir) do
    yield(container)
  end
ensure
  container.destroy!
end