Class: Piggly::Config

Inherits:
Object show all
Defined in:
lib/piggly/config.rb,
lib/piggly/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.mkpath(root, file = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/piggly/config.rb', line 16

def mkpath(root, file=nil)
  if file.nil?
    FileUtils.makedirs(root)
    root
  else
    path = path(root, file)
    FileUtils.makedirs(File.dirname(path))
    path
  end
end

.path(root, file = nil) ⇒ Object



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

def path(root, file=nil)
  if file.nil?
    root
  else
    file[%r{^\.\.|^\/|^(?:[A-Z]:)?/}i] ?
      file : # ../path, /path, or D:\path that isn't relative to root
      File.join(root, file)
  end
end

Instance Method Details

#mkpath(*args) ⇒ Object



64
65
66
# File 'lib/piggly/config.rb', line 64

def mkpath(*args)
  self.class.mkpath(*args)
end

#path(*args) ⇒ Object



60
61
62
# File 'lib/piggly/config.rb', line 60

def path(*args)
  self.class.path(*args)
end