Class: ProjectService

Inherits:
Object
  • Object
show all
Defined in:
lib/spinjector/project_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(project, logger) ⇒ ProjectService

Returns a new instance of ProjectService.

Parameters:

  • project (Xcodeproj::Project)


15
16
17
18
# File 'lib/spinjector/project_service.rb', line 15

def initialize(project, logger)
    @project = project
    @logger = logger
end

Instance Method Details

#update_scripts_in_targets(configuration) ⇒ Object

Parameters:

  • configuration (Configuration)

    containing all scripts to add in each target



22
23
24
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
# File 'lib/spinjector/project_service.rb', line 22

def update_scripts_in_targets(configuration)
    @project.targets.each do |target|
        @insertion_offset_after_compile = 0
        @insertion_offset_after_headers = 0
        target_configuration = configuration.targets.find { |conf_target| conf_target.name == target.name }
        if target_configuration == nil
            @logger.log "No Spinjector managed build phases in target #{target}"
            remove_all_scripts(target)
            next
        end
        @logger.log "Configurating target #{target}"
        scripts_to_apply = target_configuration.scripts_names.map { |name| BUILD_PHASE_PREFIX + name }.to_set
        native_target_script_phases = target.shell_script_build_phases.select do |bp|
            !bp.name.nil? && bp.name.start_with?(BUILD_PHASE_PREFIX)
        end
        native_target_script_phases.each do |script_phase|
            if scripts_to_apply.include?(script_phase.name)
                # Update existing script phase with new values
                script_configuration = target_configuration.scripts.find { |script|
                    BUILD_PHASE_PREFIX + script.name == script_phase.name
                }
                update_script_in_target(script_phase, script_configuration, target)
                scripts_to_apply.delete(script_phase.name)
            elsif
                target.build_phases.delete(script_phase)
                # Remove now defunct script phase
            end
        end
        # We may miss scripts that are yet to be added to the pbxproj target, this is fixed in the following method
        reorder_and_add_missing_script_phases_of(target, target_configuration)
    end
end