Module: Construct::PathExtensions

Included in:
Helpers
Defined in:
lib/construct/path_extensions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#construct__chdir_defaultObject

Returns the value of attribute construct__chdir_default.



4
5
6
# File 'lib/construct/path_extensions.rb', line 4

def construct__chdir_default
  @construct__chdir_default
end

Instance Method Details

#chdir(&block) ⇒ Object

Note: Pathname implements #chdir directly, but it is deprecated in favor of Dir.chdir



43
44
45
# File 'lib/construct/path_extensions.rb', line 43

def chdir(&block)
  Dir.chdir(self, &block)
end

#destroy!Object



47
48
49
# File 'lib/construct/path_extensions.rb', line 47

def destroy!
  rmtree
end

#directory(path, chdir = construct__chdir_default) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/construct/path_extensions.rb', line 6

def directory(path,chdir=construct__chdir_default)
  subdir = (self + path)
  subdir.mkpath
  subdir.extend(PathExtensions)
  subdir.maybe_change_dir(chdir) do
    yield(subdir) if block_given?
  end
  subdir
end

#file(filepath, contents = nil, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/construct/path_extensions.rb', line 16

def file(filepath,contents=nil,&block)
  path = (self+filepath)
  path.dirname.mkpath
  File.open(path,'w') do |f|
    if(block)
      if(block.arity==1)
        block.call(f)
      else
        f << block.call
      end
    else
      f << contents
    end
  end
  path
end

#maybe_change_dir(chdir, &block) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/construct/path_extensions.rb', line 33

def maybe_change_dir(chdir, &block)
  if(chdir)
    self.chdir(&block)
  else
    block.call
  end
end