<commit_before>require 'deep_clone'
require_relative 'spec_target_configuration_dsl_12X'
require_relative 'spec_target_project_ref_dsl_12X'

module StructCore
	class SpecTargetDSL12X
		def initialize
			@target = nil
			@type = nil
			@raw_type = nil
			@profiles = []
			@project_configurations = []
			@project_base_dir = nil
		end

		attr_accessor :project_configurations
		attr_accessor :project_base_dir
		attr_accessor :target

		def type(type)
			@type = type
			@type = ":#{type}" if type.is_a?(Symbol)
			# : at the start of the type is shorthand for 'com.apple.product-type.'
			if @type.start_with? ':'
				@type[0] = ''
				@raw_type = @type
				@type = "com.apple.product-type.#{@type}"
			else
				@raw_type = @type
			end

			@profiles << @raw_type
			@target.type = @type
		end

		def profile(profile)
			return unless profile.is_a?(String) && !profile.empty?
			@profiles << profile
		end

		def platform(platform)
			return unless platform.is_a?(String) || platform.is_a?(Symbol)
			# TODO: Add support for 'tvos', 'watchos'
			platform = platform.to_s if platform.is_a?(Symbol)
			unless %w(ios mac).include? platform
				puts Paint["Warning: Target #{target_name} specifies unrecognised platform '#{platform}'. Ignoring...", :yellow]
				return
			end

			@profiles << "platform:#{platform}"
		end

		def configuration(name = nil, &block)
			dsl = StructCore::SpecTargetConfigurationDSL12X.new

			if name.nil?
				dsl.configuration = StructCore::Specfile::Target::Configuration.new nil, {}, []
				dsl.instance_eval(&block)

				config = dsl.configuration
				config.profiles = @profiles
				@target.configurations = @project_configurations.map { |project_config|
					target_config = DeepClone.clone config
					target_config.name = project_config.name
					target_config
				}
			else
				dsl.configuration = StructCore::Specfile::Target::Configuration.new name, {}, []
				dsl.instance_eval(&block)

				config = dsl.configuration
				return if config.profiles.empty? && (config.source.nil? || config.source.empty?)

				config.profiles = @profiles
				@target.configurations << config
			end
		end

		def source_dir(path)
			return unless path.is_a?(String) && !path.empty?
			@target.source_dir << File.join(@project_base_dir, path)<commit_msg>Fixed spec target DSL configuration factory<commit_after>require 'deep_clone'
require_relative 'spec_target_configuration_dsl_12X'
require_relative 'spec_target_project_ref_dsl_12X'

module StructCore
	class SpecTargetDSL12X
		def initialize
			@target = nil
			@type = nil
			@raw_type = nil
			@profiles = []
			@project_configurations = []
			@project_base_dir = nil
		end

		attr_accessor :project_configurations
		attr_accessor :project_base_dir
		attr_accessor :target

		def type(type)
			@type = type
			@type = ":#{type}" if type.is_a?(Symbol)
			# : at the start of the type is shorthand for 'com.apple.product-type.'
			if @type.start_with? ':'
				@type[0] = ''
				@raw_type = @type
				@type = "com.apple.product-type.#{@type}"
			else
				@raw_type = @type
			end

			@profiles << @raw_type
			@target.type = @type
		end

		def profile(profile)
			return unless profile.is_a?(String) && !profile.empty?
			@profiles << profile
		end

		def platform(platform)
			return unless platform.is_a?(String) || platform.is_a?(Symbol)
			# TODO: Add support for 'tvos', 'watchos'
			platform = platform.to_s if platform.is_a?(Symbol)
			unless %w(ios mac).include? platform
				puts Paint["Warning: Target #{target_name} specifies unrecognised platform '#{platform}'. Ignoring...", :yellow]
				return
			end

			@profiles << "platform:#{platform}"
		end

		def configuration(name = nil, &block)
			dsl = StructCore::SpecTargetConfigurationDSL12X.new

			if name.nil?
				dsl.configuration = StructCore::Specfile::Target::Configuration.new nil, {}, []
				dsl.instance_eval(&block)

				config = dsl.configuration
				config.profiles = @profiles if config.source.nil? || config.source.empty?
				@target.configurations = @project_configurations.map { |project_config|
					target_config = DeepClone.clone config
					target_config.name = project_config.name
					target_config
				}
			else
				dsl.configuration = StructCore::Specfile::Target::Configuration.new name, {}, []
				dsl.instance_eval(&block)

				config = dsl.configuration
				config.profiles = @profiles if config.source.nil? || config.source.empty?

				@target.configurations << config
			end
		end

		def source_dir(path)
			return unless path.is_a?(String) && !path.empty?
			@target.source_dir << File.join(@project_base_dir, path)
{'fraction_non_alphanumeric': 0.11994756390648896, 'fraction_numerical': 0.003932707013327507, 'mean_word_length': 3.8547189819724283, 'pattern_counts': {'":': 2, '<': 23, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5104110', 'n_tokens_mistral': 1782, 'n_tokens_neox': 1486, 'n_words': 323}