class StructCore::SpecProcessor

Public Class Methods

new(project_file, dry_run = false, selected_variants = []) click to toggle source
# File lib/spec/processor/spec_processor.rb, line 13
def initialize(project_file, dry_run = false, selected_variants = [])
        return if project_file.to_s.empty?
        @project_file = project_file
        @dry_run = dry_run
        @selected_variants = selected_variants || []
end

Public Instance Methods

process(project_component = nil, scripts_component = nil) click to toggle source

@param project_component [StructCore::Processor::ProjectComponent] @param scripts_component [StructCore::SpecScriptsProcessor]

# File lib/spec/processor/spec_processor.rb, line 22
def process(project_component = nil, scripts_component = nil)
        full_project_path, target_structure = resolve_project_data @project_file
        project_component ||= StructCore::Processor::ProjectComponent.new(target_structure, File.dirname(full_project_path))
        scripts_component ||= StructCore::SpecScriptsProcessor.new

        source_dsl = process_source_dsl full_project_path
        scripts_component.pre_generate source_dsl

        outputs = project_component.process source_dsl, @selected_variants
        return if outputs.empty?

        puts "\n" unless @dry_run

        process_outputs outputs, scripts_component, source_dsl
        outputs
end
process_outputs(outputs, scripts_component, source_dsl) click to toggle source
# File lib/spec/processor/spec_processor.rb, line 74
def process_outputs(outputs, scripts_component, source_dsl)
        outputs.each { |output|
                if @dry_run
                        print output.dsl if output.dsl.is_a?(Xcodeproj::Project)
                        print output.dsl if output.dsl.is_a?(Xcodeproj::XCScheme)
                        print output.dsl, raw: true if output.dsl.is_a?(StructCore::Specfile)
                else
                        StructCore::Specwriter.new.write_spec output.dsl, output.path unless output.path.end_with?('.xcodeproj', '.xcscheme')
                        output.dsl.save output.path if output.path.end_with? '.xcodeproj'
                        output.dsl.save_as output.options[:project], output.options[:name] if output.path.end_with? '.xcscheme'
                        puts Paint["Saved '#{output.path}'"]
                end

                scripts_component.post_generate source_dsl, output.dsl
        }
end

Private Instance Methods

print(dsl, options = {}) click to toggle source
process_source_dsl(full_project_path) click to toggle source
# File lib/spec/processor/spec_processor.rb, line 60
def process_source_dsl(full_project_path)
        # TODO: Replace with Spec & DSL processor
        source_dsl = nil
        source_dsl = StructCore::Specfile.parse full_project_path if full_project_path.end_with?('.yml')
        source_dsl = StructCore::Specfile.parse full_project_path if full_project_path.end_with?('.yaml')
        source_dsl = StructCore::Specfile.parse full_project_path if full_project_path.end_with?('.json')
        source_dsl = StructCore::SpecBuilder.build full_project_path if full_project_path.end_with?('Specfile')
        source_dsl = Xcodeproj::Project.open full_project_path if full_project_path.end_with?('.xcodeproj')

        raise StandardError.new "Unrecognised project format: #{File.basename(full_project_path)}" if source_dsl.nil?

        source_dsl
end
resolve_project_data(project_file) click to toggle source
# File lib/spec/processor/spec_processor.rb, line 39
def resolve_project_data(project_file)
        full_project_path = project_file.to_s
        full_project_path = File.join(Dir.pwd, full_project_path) unless Pathname.new(full_project_path).absolute?

        if full_project_path.end_with? '.xcodeproj'
                target_structure = :spec
        elsif full_project_path.end_with? '.yaml'
                target_structure = :xcodeproj
        elsif full_project_path.end_with? '.yml'
                target_structure = :xcodeproj
        elsif full_project_path.end_with? '.json'
                target_structure = :xcodeproj
        elsif File.basename(full_project_path) == 'Specfile'
                target_structure = :xcodeproj
        else
                raise StandardError.new "Unrecognised project format: #{File.basename(full_project_path)}"
        end

        [full_project_path, target_structure]
end