class ProjectHelper
Constants
- PROJECTS
Public Class Methods
new()
click to toggle source
# File lib/project_helper.rb, line 7 def initialize @project = Xcodeproj::Project.open(xcode_project_file) end
Public Instance Methods
add_shell_script(target, name, script)
click to toggle source
# File lib/project_helper.rb, line 33 def add_shell_script(target, name, script) if target.shell_script_build_phases.to_a.index { |phase| phase.name == name } puts "Skipping adding \"#{name}\" script for target #{target} as it already exist" else target.new_shell_script_build_phase(name).shell_script = script save_changes end end
duplicate_configurations(configurations_hash)
click to toggle source
# File lib/project_helper.rb, line 42 def duplicate_configurations(configurations_hash) configurations_hash.each do |name, base| @project.targets.each do |target| base_configuration, project_configuration = find_configurations(base, target) if !base_configuration || !project_configuration puts "unable to find configurations for #{base}" next end target.build_configurations << clone_configuration(base_configuration, name) @project.build_configurations << clone_configuration(project_configuration, name) end end save_changes end
enable_options(options)
click to toggle source
# File lib/project_helper.rb, line 11 def enable_options(options) @project.build_configurations.each do |configuration| options.each do |option| configuration.build_settings[option] = 'YES' end end save_changes end
select_target_for_name(name)
click to toggle source
# File lib/project_helper.rb, line 61 def select_target_for_name(name) targets = @project.targets.to_a.select { |t| t.name.end_with? name.to_s } targets = @project.targets.to_a if targets.empty? choose_item("Which target should I use for #{name}?", targets) end
set_build_settings(build_settings)
click to toggle source
# File lib/project_helper.rb, line 20 def set_build_settings(build_settings) @project.build_configurations.each do |configuration| build_settings.each do |configuration_name, settings| if configuration_name.to_s.downcase == "crafter_common" || configuration.name.downcase == configuration_name.to_s.downcase settings.each do |key, value| configuration.build_settings[key] = value end end end end save_changes end
Private Instance Methods
available_targets()
click to toggle source
# File lib/project_helper.rb, line 108 def available_targets @project.targets.to_a.delete_if { |t| t.name.end_with?('Tests') } end
choose_item(title, objects)
click to toggle source
# File lib/project_helper.rb, line 95 def choose_item(title, objects) if objects.empty? raise 'Could not locate any Targets!' elsif objects.size == 1 objects.first else choose do |menu| menu.prompt = title objects.map { |object| menu.choice(object) } end end end
clone_configuration(base_configuration, name)
click to toggle source
# File lib/project_helper.rb, line 69 def clone_configuration(base_configuration, name) build_config = @project.new(Xcodeproj::Project::XCBuildConfiguration) build_config.name = name.to_s build_config.build_settings = base_configuration build_config end
find_configurations(base, target)
click to toggle source
# File lib/project_helper.rb, line 76 def find_configurations(base, target) base_configuration = target.build_configuration_list.build_configurations.find { |t| t.name.downcase == base.to_s.downcase } base_configuration = base_configuration.build_settings if base_configuration project_configuration = @project.build_configurations.find { |t| t.name.downcase == base.to_s.downcase } project_configuration = project_configuration.build_settings if project_configuration return base_configuration, project_configuration end
save_changes()
click to toggle source
# File lib/project_helper.rb, line 112 def save_changes @project.save xcode_project_file end
xcode_project_file()
click to toggle source
# File lib/project_helper.rb, line 85 def xcode_project_file @xcode_project_file ||= choose_item('Project', PROJECTS) if @xcode_project_file == 'Pods.xcodeproj' raise 'Can not run in the Pods directory. $ cd .. maybe?' end @xcode_project_file end