Sha256: 4db95248a09f68c8b1983277b9b72276e0883d6bb5af538db6dd6adc5fd7f0f4

Contents?: true

Size: 1.43 KB

Versions: 6

Compression:

Stored size: 1.43 KB

Contents

require 'ostruct'

module Shenzhen::XcodeBuild
  class Info < OpenStruct; end

  class Error < StandardError; end
  class NilOutputError < Error; end

  class << self
    def info
      output = `xcodebuild -list 2> /dev/null`
      raise Error.new $1 if /^xcodebuild\: error\: (.+)$/ === output
      raise NilOutputError unless /\S/ === output

      lines = output.split(/\n/)
      hash = {}
      group = nil

      hash[:project] = lines.shift.match(/\"(.+)\"\:/)[1]

      lines.each do |line|
        if /\:$/ === line
          group = line.strip[0...-1].downcase.gsub(/\s+/, '_')
          hash[group] = []
          next
        end

        unless group.nil? or /\.$/ === line
          hash[group] << line.strip
        end
      end

      hash.each do |group, values|
        next unless Array === values
        values.delete("") and values.uniq! 
      end

      Info.new(hash)
    end

    def settings(flags = [])
      output = `xcodebuild #{flags.join(' ')} -showBuildSettings 2> /dev/null`
      raise Error.new $1 if /^xcodebuild\: error\: (.+)$/ === output
      raise NilOutputError unless /\S/ === output

      lines = output.split(/\n/)
      lines.shift

      hash = {}
      lines.each do |line|
        key, value = line.split(/\=/).collect(&:strip)
        hash[key] = value
      end

      hash
    end

    def version
      output = `xcodebuild -version`
      output.scan(/([\d\.?]+)/).flatten.first rescue nil
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shenzhen-0.2.1 ./lib/shenzhen/xcodebuild.rb
shenzhen-0.2.0 ./lib/shenzhen/xcodebuild.rb
shenzhen-0.1.0 ./lib/shenzhen/xcodebuild.rb
shenzhen-0.0.3 ./lib/shenzhen/xcodebuild.rb
shenzhen-0.0.2 ./lib/shenzhen/xcodebuild.rb
shenzhen-0.0.1 ./lib/shenzhen/xcodebuild.rb