Sha256: 63f4364492eae9571ce05d6b135af159d3023e3033f1ba576d4252ee61afe432

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

require 'xcodeproj'
require 'pathname'

module IosToolchain
  class ProjectAnalyzer
    attr_reader :project_root, :project_path

    def initialize(project_root)
      @project_root = Pathname.new(project_root).realpath.to_s
      @project_path = find_project_path!
      @project = Xcodeproj::Project.open(@project_path)
    end

    def default_scheme
      shared_schemes.find { |name| name == project_name }
    end

    def default_sdk
    end

    def crashlytics_framework_path
      Dir.glob("#{project_root}/**/Crashlytics.framework").first
    end

    def app_targets
      project.targets.map(&:name).find_all do |name|
        !name.include?('Tests')
      end
    end

    def test_targets
      project.targets.map(&:name).find_all do |name|
        name.include?('Tests') && !name.include?('UITests')
      end
    end

    def ui_test_targets
      project.targets.map(&:name).find_all do |name|
        name.include?('UITests')
      end
    end

    private

    def shared_schemes
      Xcodeproj::Project.schemes(project_path)
    end

    def project_name
      project_path.split(File::SEPARATOR)[-1].split('.')[-2]
    end

    def find_project_path!
      Dir.glob(File.join(project_root, '/*.xcodeproj')).first.tap do |project|
        return project unless project.nil?

        error_message  = "No .xcodeproj file was found in #{project_root} "
        error_message += "Run `rake toolchain:bootstrap[/path/containing/project/]`"
        throw error_message
      end
    end

    attr_reader :project
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ios_toolchain-0.2.2 lib/ios_toolchain/project_analyzer.rb
ios_toolchain-0.2.1 lib/ios_toolchain/project_analyzer.rb
ios_toolchain-0.2.0 lib/ios_toolchain/project_analyzer.rb