Class: Phoenx::Target::HeaderBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/phoenx/use_cases/target/add_header.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, target, target_spec) ⇒ HeaderBuilder

Returns a new instance of HeaderBuilder.



11
12
13
14
15
16
# File 'lib/phoenx/use_cases/target/add_header.rb', line 11

def initialize(project, target, target_spec)
	@project = project
	@target = target
	@target_spec = target_spec
	@umbrella_headers = []
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



6
7
8
# File 'lib/phoenx/use_cases/target/add_header.rb', line 6

def project
  @project
end

#targetObject (readonly)

Returns the value of attribute target.



7
8
9
# File 'lib/phoenx/use_cases/target/add_header.rb', line 7

def target
  @target
end

#target_specObject (readonly)

Returns the value of attribute target_spec.



8
9
10
# File 'lib/phoenx/use_cases/target/add_header.rb', line 8

def target_spec
  @target_spec
end

#umbrella_headersObject (readonly)

Returns the value of attribute umbrella_headers.



9
10
11
# File 'lib/phoenx/use_cases/target/add_header.rb', line 9

def umbrella_headers
  @umbrella_headers
end

Instance Method Details

#add_header(header, attributes) ⇒ Object



70
71
72
73
74
# File 'lib/phoenx/use_cases/target/add_header.rb', line 70

def add_header(header, attributes)
	file = Phoenx.get_or_add_file(@project, header)
	build_file = @target.headers_build_phase.add_file_reference(file, true)
	build_file.settings = attributes
end

#add_headers(header_files, attributes, add_to_umbrella_header) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/phoenx/use_cases/target/add_header.rb', line 54

def add_headers(header_files, attributes, add_to_umbrella_header)
	headers = Phoenx.merge_files_array(header_files)
	unless !header_files || header_files.empty? || !headers.empty?
		puts "No #{attributes["ATTRIBUTES"].first} headers found".yellow
	end
	Phoenx.add_groups_for_files(@project, headers)
	headers.each do |header|
		self.add_header(header, attributes)
	end
	if add_to_umbrella_header
		@umbrella_headers += headers
	else 
		@umbrella_headers -= headers
	end
end

#add_private_headersObject



33
34
35
# File 'lib/phoenx/use_cases/target/add_header.rb', line 33

def add_private_headers
	self.add_headers(@target_spec.private_headers, ATTRIBUTES_PRIVATE_HEADERS, false)
end

#add_project_headersObject



29
30
31
# File 'lib/phoenx/use_cases/target/add_header.rb', line 29

def add_project_headers
	self.add_headers(@target_spec.project_headers, ATTRIBUTES_PROJECT_HEADERS, true)
end

#add_public_headersObject



25
26
27
# File 'lib/phoenx/use_cases/target/add_header.rb', line 25

def add_public_headers
	self.add_headers(@target_spec.public_headers, ATTRIBUTES_PUBLIC_HEADERS, true)
end

#buildObject



18
19
20
21
22
23
# File 'lib/phoenx/use_cases/target/add_header.rb', line 18

def build
	self.add_public_headers
	self.add_project_headers
	self.add_private_headers
	self.generate_umbrella_header
end

#generate_umbrella_headerObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/phoenx/use_cases/target/add_header.rb', line 37

def generate_umbrella_header
	unless @target_spec.umbrella_header == nil
		entries = @umbrella_headers.map{ |header| 
			unless @target_spec.module_name == nil
				import = '<' + @target_spec.module_name + '/' + File.basename(header) + '>'
			else
				import = '"'  + File.basename(header) + '"'
			end
			'#import ' + import
		}.sort
		open(@target_spec.umbrella_header, "w") { |file| 
			entries.each { |header| file.puts header }
		}
		self.add_header(@target_spec.umbrella_header, ATTRIBUTES_PUBLIC_HEADERS)
	end
end