Class: SwiftGenerator::SwiftFile

Inherits:
Object
  • Object
show all
Defined in:
lib/swift_generator/code_generation/swift_class_generation.rb

Overview

A Swift File to be generated. This file contains one or more elements Elements can be classes (Future: Structs, Enums, Functions)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, root_path, is_user_file: false, company_name: "<My Entity>") ⇒ SwiftFile

Returns a new instance of SwiftFile.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 20

def initialize (name, root_path, is_user_file:false, company_name:"<My Entity>")
	name += '.swift' unless name.end_with?( '.swift' )
	@file_name = name
	@file_path = File.join(root_path, @file_name)

   #puts( "--- SwiftFile name = #{name} root_path = #{root_path} file_path = #{@file_path}" )

   @is_user_file = is_user_file
	@elements = []
	@import_statements = []
   @include_editing_warnings = false
   @company_name = company_name
end

Instance Attribute Details

#company_nameObject

Returns the value of attribute company_name.



17
18
19
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 17

def company_name
  @company_name
end

#elementsObject

Returns the value of attribute elements.



14
15
16
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 14

def elements
  @elements
end

#file_nameObject

Returns the value of attribute file_name.



12
13
14
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 12

def file_name
  @file_name
end

#file_pathObject

Returns the value of attribute file_path.



13
14
15
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 13

def file_path
  @file_path
end

#import_statementsObject

Returns the value of attribute import_statements.



15
16
17
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 15

def import_statements
  @import_statements
end

#include_editing_warningsObject

Returns the value of attribute include_editing_warnings.



18
19
20
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 18

def include_editing_warnings
  @include_editing_warnings
end

#is_user_fileObject

Returns the value of attribute is_user_file.



16
17
18
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 16

def is_user_file
  @is_user_file
end

Instance Method Details

#add_element(swift_class) ⇒ Object



34
35
36
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 34

def add_element(swift_class)
	@elements << swift_class
end

#add_import(module_name) ⇒ Object

Parameters:

  • module_name (String)


53
54
55
56
57
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 53

def add_import(module_name)
	import_statement = "import #{module_name}"
	return if @import_statements.include?(import_statement)
	@import_statements << import_statement
end

#prepare_for_generationObject



46
47
48
49
50
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 46

def prepare_for_generation
	@elements.each do |element|
		element.prepare_for_generation
	end
end

#prepare_supporting_elementsObject

Called before all other generation-time methods. Give user-defined elements ( classes, etc. ) the opportunity to construct other related or required elements



40
41
42
43
44
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 40

def prepare_supporting_elements
	@elements.each do |element|
		element.prepare_supporting_elements
	end
end