Class: ModelGenerator
- Inherits:
-
Object
- Object
- ModelGenerator
- Defined in:
- lib/ModelGenerator/ModelGenerator.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#commandTask ⇒ Object
readonly
Returns the value of attribute commandTask.
-
#db_generator ⇒ Object
readonly
Returns the value of attribute db_generator.
-
#enum_generator ⇒ Object
readonly
Returns the value of attribute enum_generator.
-
#json_generator ⇒ Object
readonly
Returns the value of attribute json_generator.
-
#name ⇒ Object
Returns the value of attribute name.
-
#nimbus_generator ⇒ Object
readonly
Returns the value of attribute nimbus_generator.
-
#organization ⇒ Object
readonly
Returns the value of attribute organization.
-
#project_name ⇒ Object
readonly
Returns the value of attribute project_name.
Instance Method Summary collapse
- #analyze_command(args) ⇒ Object
- #generate_header ⇒ Object
- #generate_property_list ⇒ Object
- #generate_source ⇒ Object
-
#initialize ⇒ ModelGenerator
constructor
A new instance of ModelGenerator.
- #seek_project_info ⇒ Object
Constructor Details
#initialize ⇒ ModelGenerator
Returns a new instance of ModelGenerator.
22 23 24 25 26 |
# File 'lib/ModelGenerator/ModelGenerator.rb', line 22 def initialize @organization="<" +"#" + "organization" + "#" + ">" @project_name="<" +"#" + "project_name" + "#" + ">" ="Unknow Author" end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
13 14 15 |
# File 'lib/ModelGenerator/ModelGenerator.rb', line 13 def end |
#commandTask ⇒ Object (readonly)
Returns the value of attribute commandTask.
16 17 18 |
# File 'lib/ModelGenerator/ModelGenerator.rb', line 16 def commandTask @commandTask end |
#db_generator ⇒ Object (readonly)
Returns the value of attribute db_generator.
17 18 19 |
# File 'lib/ModelGenerator/ModelGenerator.rb', line 17 def db_generator @db_generator end |
#enum_generator ⇒ Object (readonly)
Returns the value of attribute enum_generator.
19 20 21 |
# File 'lib/ModelGenerator/ModelGenerator.rb', line 19 def enum_generator @enum_generator end |
#json_generator ⇒ Object (readonly)
Returns the value of attribute json_generator.
18 19 20 |
# File 'lib/ModelGenerator/ModelGenerator.rb', line 18 def json_generator @json_generator end |
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'lib/ModelGenerator/ModelGenerator.rb', line 12 def name @name end |
#nimbus_generator ⇒ Object (readonly)
Returns the value of attribute nimbus_generator.
20 21 22 |
# File 'lib/ModelGenerator/ModelGenerator.rb', line 20 def nimbus_generator @nimbus_generator end |
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
15 16 17 |
# File 'lib/ModelGenerator/ModelGenerator.rb', line 15 def organization @organization end |
#project_name ⇒ Object (readonly)
Returns the value of attribute project_name.
14 15 16 |
# File 'lib/ModelGenerator/ModelGenerator.rb', line 14 def project_name @project_name end |
Instance Method Details
#analyze_command(args) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ModelGenerator/ModelGenerator.rb', line 32 def analyze_command(args) @commandTask=CommandTask.new(args) @commandTask.parseCommand @db_generator=DBGenerator.new(@commandTask) @json_generator=JsonGenerator.new(@commandTask) @enum_generator=EnumGenerator.new(@commandTask.property_em_name_type_hash) @nimbus_generator=NimbusGenerator.new(@commandTask) return @commandTask end |
#generate_header ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ModelGenerator/ModelGenerator.rb', line 44 def generate_header parent_path=File.('..', __FILE__) headerPath="#{parent_path}/resource/Model/ModelTemple.h" annouce=Announcement.new annouce.name=@commandTask.entity_name file_declare=annouce.createDeclare entity_name=@commandTask.parent_class ? (@commandTask.entity_name + " : " + @commandTask.parent_class) : (@commandTask.entity_name + ": MTLModel<MTLJSONSerializing>") to_header_content=File.read(headerPath) header_import="" if @commandTask.parent_class header_import="#import \"#{@commandTask.entity_name}.h\"\n" end to_header_content.gsub!(CommonParam.header_import,header_import) to_header_content.gsub!(CommonParam.file_declare,file_declare) to_header_content.gsub!(CommonParam.enum_declare,@enum_generator.generate_em_declare) to_header_content.gsub!(CommonParam.entity_name,entity_name) to_header_content.gsub!(CommonParam.property_declare,self.generate_property_list) f= File.new("#{Dir.pwd}/#{@commandTask.entity_name}.h","w") f.syswrite(to_header_content) end |
#generate_property_list ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/ModelGenerator/ModelGenerator.rb', line 119 def generate_property_list property_list_content="" @commandTask.property_name_type_hash.each do |name,type| var_type=type reference_type=CommonParam.reference_type_mapping[var_type]; type_name= @commandTask.property_em_name_type_hash[name] if type_name property_type=@commandTask.property_em_name_type_hash[name] else property_type=CommonParam.type_mapping[var_type] end property_name=name property_list_content << "@property(nonatomic,#{reference_type}) #{property_type} #{property_name};\n" end return property_list_content end |
#generate_source ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ModelGenerator/ModelGenerator.rb', line 74 def generate_source parent_path=File.('..', __FILE__) source_path="#{parent_path}/resource/Model/ModelTemple.m" to_source_content=File.read(source_path) annouce=Announcement.new annouce.name=@commandTask.entity_name file_declare=annouce.createDeclare entity_name=@commandTask.entity_name to_source_content.gsub!(CommonParam.file_declare,file_declare) to_source_content.gsub!(CommonParam.entity_name,entity_name) if @json_generator.generate_property_mapping to_source_content.gsub!(CommonParam.property_mapping,@json_generator.generate_property_mapping) end if @json_generator.generate_json_column_mapping to_source_content.gsub!(CommonParam.json_column_mapping,@json_generator.generate_json_column_mapping) end if @json_generator.generate_formater to_source_content.gsub!(CommonParam.type_transformer,@json_generator.generate_formater) end if @db_generator.generate_table_column_declare to_source_content.gsub!(CommonParam.table_column_declare,@db_generator.generate_table_column_declare) end if @db_generator.generate_table_name to_source_content.gsub!(CommonParam.table_name,@db_generator.generate_table_name) end if @db_generator.generate_primary_key to_source_content.gsub!(CommonParam.table_primary_key,@db_generator.generate_primary_key) end if @db_generator.generate_table_mapping to_source_content.gsub!(CommonParam.table_mapping,@db_generator.generate_table_mapping) end if @nimbus_generator.generate_need_methods to_source_content.gsub!(CommonParam.nimbus_method,@nimbus_generator.generate_need_methods) end f= File.new("#{Dir.pwd}/#{entity_name}.m","w") f.syswrite(to_source_content) end |
#seek_project_info ⇒ Object
28 29 30 |
# File 'lib/ModelGenerator/ModelGenerator.rb', line 28 def seek_project_info end |