Module: Bake::Utils

Defined in:
lib/common/utils.rb

Defined Under Namespace

Modules: OS

Class Method Summary collapse

Class Method Details

.deep_copy(x) ⇒ Object



90
91
92
# File 'lib/common/utils.rb', line 90

def self.deep_copy(x)
  Marshal.load(Marshal.dump(x))
end

.flagSplit(str, removeQuotes) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/common/utils.rb', line 25

def self.flagSplit(str, removeQuotes)
  return [] if str == ""
  return [str] unless str.include?" "

  hasQuote = false
  hasDoubleQuote = false
  hadQuote = false
  ar = []
  s = ""

  str.split("").each do |i|
    hasDoubleQuote = !hasDoubleQuote if !hasQuote && i == '"'
    hasQuote = !hasQuote if !hasDoubleQuote && i == '\''
    hadQuote = true if hasDoubleQuote || hasQuote
    if i == ' '
      if !hasDoubleQuote && !hasQuote
        if hadQuote && removeQuotes
          ar << s[1..-2] if s.length > 2
          hadQuote = false
        else
          ar << s if s.length > 0
        end
        s = ""
        next
      end
    end
    s << i
  end
  if !hasDoubleQuote && !hasQuote && hadQuote && removeQuotes
    ar << s[1..-2] if s.length > 2
  elsif s.length > 0
    ar << s
  end
  ar
end

.gitIgnore(folder, mode = :report) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/common/utils.rb', line 7

def self.gitIgnore(folder, mode = :report)
  gitignore = folder + "/.gitignore"
  begin
    FileUtils::mkdir_p(folder)
    if !File.exist?(gitignore)
      File.write(gitignore, ".\n")
    end
  rescue Exception=>e
    if mode != :silent && Bake.options.verbose >= 3
      Bake.formatter.printWarning("Warning: Could not write file #{gitignore}")
      if Bake.options.debug
        puts e.message
        puts e.backtrace
      end
    end
  end
end