Sha256: a37b94147de105f43d532dca860aef1b4642a74b1fbaf38b098769c7df53ef39

Contents?: true

Size: 1.93 KB

Versions: 13

Compression:

Stored size: 1.93 KB

Contents

require 'rbconfig'

module Bake

  module Utils
    
    def self.gitIgnore(folder)
      FileUtils::mkdir_p(folder)
      gitignore = folder + "/.gitignore"
      if !File.exist?(gitignore)
        File.write(gitignore, ".\n")
      end
    end

    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

    # Simple helper query the operating system we are running in
    module OS

      # Is it windows
      def OS.windows?
        (RUBY_PLATFORM =~ /cygwin|mswin|msys|mingw|bccwin|wince|emx|emc/) != nil
      end

      def OS.name
        @os ||= (
          host_os = RbConfig::CONFIG['host_os']
          case host_os
          when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
            "Windows"
          when /darwin|mac os/
            "Mac"
          when /linux/
            "Linux"
          when /solaris|bsd/
            "Unix"
          else
            Bake.formatter.printError("Unknown OS: #{host_os.inspect}")
            ExitHelper.exit(1)
          end
        )
      end

    end

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

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
bake-toolkit-2.63.1 lib/common/utils.rb
bake-toolkit-2.63.0 lib/common/utils.rb
bake-toolkit-2.62.0 lib/common/utils.rb
bake-toolkit-2.61.0 lib/common/utils.rb
bake-toolkit-2.60.2 lib/common/utils.rb
bake-toolkit-2.60.0 lib/common/utils.rb
bake-toolkit-2.59.0 lib/common/utils.rb
bake-toolkit-2.58.0 lib/common/utils.rb
bake-toolkit-2.57.0 lib/common/utils.rb
bake-toolkit-2.56.0 lib/common/utils.rb
bake-toolkit-2.55.1 lib/common/utils.rb
bake-toolkit-2.55.0 lib/common/utils.rb
bake-toolkit-2.54.3 lib/common/utils.rb