22require "erb"
33require "Shellwords"
44require "optparse"
5- require_relative "../source/CSVParser "
6- require_relative "../source/YMLParser "
7- require_relative "../source/YMLSerializer "
5+ require_relative "../source/csv_parser "
6+ require_relative "../source/yml_parser "
7+ require_relative "../source/yml_serializer "
88
99@options = {
1010 MIGRATION : false ,
@@ -50,7 +50,7 @@ def main
5050 output_filename = @options [ :OUTPUT_FILE ]
5151
5252 if input_filename . end_with? ( "csv" )
53- YMLSerializer . new . serialize_hash_to_YML ( definition_hash , output_filename )
53+ YMLSerializer . new . serialize_hash_to_yml ( definition_hash , output_filename )
5454 elsif input_filename . end_with? ( "yml" )
5555 serialize_hash_to_CSV ( definition_hash , output_filename )
5656 end
7575
7676def parse_input_file ( input_filename )
7777 if input_filename . end_with? ( "csv" )
78- return CSVParser . new . parse_CSV ( input_filename )
78+ return CSVParser . new . parse_csv ( input_filename )
7979 elsif input_filename . end_with? ( "yml" )
80- return YMLParser . new . parse_YML ( input_filename )
80+ return YMLParser . new . parse_yml ( input_filename )
8181 else
8282 puts "unknown input format for file #{ input_filename } "
8383 exit
@@ -92,17 +92,16 @@ def write_container_file(input_hash, output_filename)
9292 @content_array = input_hash [ :DEFINITIONS ]
9393 @dependencies = input_hash [ :DEPENDENCIES ]
9494
95- code = ERB . new ( File . read ( "#{ templates_folder ( ) } /container.erb" ) , nil , "-" ) . result
95+ code = ERB . new ( File . read ( "#{ templates_folder } /container.erb" ) , nil , "-" ) . result
9696
9797 if output_filename . nil?
9898 puts code
9999 else
100- File . open ( output_filename , 'w' ) do |file_to_write_to |
100+ File . open ( output_filename , "w" ) do |file_to_write_to |
101101 file_to_write_to . puts code
102102 puts "Generated code in #{ output_filename } "
103103 end
104104 end
105-
106105end
107106
108107def write_migration_file ( input_hash , output_filename )
@@ -112,27 +111,26 @@ def write_migration_file(input_hash, output_filename)
112111 register_function_call_without_last_comma = definition [ :register_function_call ] . reverse . sub ( "," , "" ) . reverse
113112
114113 migration_hash = {
115- resolve_function_signature_regex : Shellwords . escape ( ".#{ definition [ :resolve_function_signature ] . split ( "->" ) . first . strip } " ) ,
114+ resolve_function_signature_regex : Shellwords . escape ( ".#{ definition [ :resolve_function_signature ] . split ( '->' ) . first . strip } " ) ,
116115 resolve_function_call : Shellwords . escape ( "#{ definition [ :resolve_function_call ] } )!" ) ,
117- register_function_signature_regex : Shellwords . escape ( ".#{ definition [ :register_function_signature ] . split ( "(" ) . first } " ) ,
116+ register_function_signature_regex : Shellwords . escape ( ".#{ definition [ :register_function_signature ] . split ( '(' ) . first } " ) ,
118117 register_function_call : Shellwords . escape ( "#{ register_function_call_without_last_comma } )" )
119118 }
120119
121120 @migration_array . push migration_hash
122121 end
123122
124- migration_code = ERB . new ( File . read ( "#{ templates_folder ( ) } /migration.erb" ) , nil , "-" ) . result
123+ migration_code = ERB . new ( File . read ( "#{ templates_folder } /migration.erb" ) , nil , "-" ) . result
125124
126125 if output_filename . nil?
127126 puts migration_code
128127 else
129128 migration_file_name = "#{ output_filename } .migration.sh"
130- File . open ( migration_file_name , 'w' ) do |file_to_write_to |
129+ File . open ( migration_file_name , "w" ) do |file_to_write_to |
131130 file_to_write_to . puts migration_code
132131 puts "Generated migration code in #{ migration_file_name } "
133132 end
134133 end
135-
136134end
137135
138136def prepare_definitions ( hash )
@@ -145,22 +143,22 @@ def prepare_definitions(hash)
145143 argument_hashes = definition [ :arguments ]
146144
147145 register_function_signature = "register"
148- register_function_signature << definition [ :component ] . gsub ( "<" , "" ) . gsub ( ">" , "" ) . gsub ( "." , " ")
146+ register_function_signature << definition [ :component ] . delete ( "<" ) . delete ( ">" ) . delete ( "." )
149147 register_function_signature << "_#{ name } " unless has_no_name
150148 register_function_signature << "(registerClosure: (resolver: ResolverType"
151- register_function_signature << ", " unless ( argument_hashes . nil? || argument_hashes . empty? )
152- register_function_signature << argument_hashes . map { |a | "#{ a [ :argument_name ] } : #{ a [ :argument_type ] } " } . join ( ", " ) unless ( argument_hashes . nil? || argument_hashes . empty? )
149+ register_function_signature << ", " unless argument_hashes . nil? || argument_hashes . empty?
150+ register_function_signature << argument_hashes . map { |a | "#{ a [ :argument_name ] } : #{ a [ :argument_type ] } " } . join ( ", " ) unless argument_hashes . nil? || argument_hashes . empty?
153151 register_function_signature << ") -> (#{ definition [ :component ] } )) -> ServiceEntry<#{ definition [ :service ] } >"
154152
155153 register_function_call = ".register("
156154 register_function_call << "#{ definition [ :service ] } .self,"
157155 register_function_call << " name: \" #{ name } \" ," unless has_no_name
158156
159157 resolve_function_signature = "resolve"
160- resolve_function_signature << definition [ :component ] . gsub ( "<" , "" ) . gsub ( ">" , "" ) . gsub ( "." , " ")
158+ resolve_function_signature << definition [ :component ] . delete ( "<" ) . delete ( ">" ) . delete ( "." )
161159 resolve_function_signature << "_#{ name } " unless has_no_name
162160 resolve_function_signature << "("
163- resolve_function_signature << argument_hashes . each_with_index . map { |a , i | "#{ a [ :argument_name ] + ' ' if i == 0 } #{ a [ :argument_name ] } : #{ a [ :argument_type ] } " } . join ( ", " ) unless ( argument_hashes . nil? || argument_hashes . empty? )
161+ resolve_function_signature << argument_hashes . each_with_index . map { |a , i | "#{ a [ :argument_name ] + ' ' if i == 0 } #{ a [ :argument_name ] } : #{ a [ :argument_type ] } " } . join ( ", " ) unless argument_hashes . nil? || argument_hashes . empty?
164162 resolve_function_signature << ") -> #{ definition [ :component ] } "
165163
166164 resolve_function_call = ".resolve("
@@ -183,13 +181,10 @@ def serialize_hash_to_CSV(hash, output_filename)
183181 if output_filename . nil?
184182 puts code
185183 else
186- File . open ( output_filename , 'w' ) do |file_to_write_to |
184+ File . open ( output_filename , "w" ) do |file_to_write_to |
187185 file_to_write_to . puts code
188186 end
189187 end
190-
191188end
192189
193- if __FILE__ == $0
194- main ( )
195- end
190+ main if __FILE__ == $PROGRAM_NAME
0 commit comments