Skip to content

Commit 3956dd8

Browse files
committed
Merge pull request #35 from Swinject/snake_case
2 parents a37e77e + f95f213 commit 3956dd8

File tree

10 files changed

+163
-164
lines changed

10 files changed

+163
-164
lines changed

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.3
1+
2.3.1

CSVParser.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
11
class CSVParser
22

3-
def parseCSV(inputFilename)
4-
returnHash = {
3+
def parse_CSV(input_filename)
4+
result_hash = {
55
:DEPENDENCIES => [],
66
:DEFINITIONS => []
77
}
88

9-
f = File.open(inputFilename)
9+
f = File.open(input_filename)
1010

1111
f.each_line do |line|
1212
if line.nil? || line.chomp.empty?
1313
# ignores empty lines
1414
elsif line.start_with?("#")
1515
# detect command
1616
if(line.start_with?("#ADD_DEPENDENCY "))
17-
returnHash[:DEPENDENCIES].push(line.split(" ")[1])
17+
result_hash[:DEPENDENCIES].push(line.split(" ")[1])
1818
elsif(line.start_with?("# ADD_DEPENDENCY "))
19-
returnHash[:DEPENDENCIES].push(line.split(" ")[2])
19+
result_hash[:DEPENDENCIES].push(line.split(" ")[2])
2020
end
2121
elsif line.start_with?("//")
2222
# ignores comments
2323
else
2424
array = line.split(";").map { |a| a.strip }
2525
arguments = array[3..-1]
26-
argumentHashes = nil
26+
argument_hashes = nil
2727
unless arguments.nil?
2828
arguments.reject { |a| a.empty? }
29-
argumentHashes = arguments.map do |a|
29+
argument_hashes = arguments.map do |a|
3030
hash = nil
3131
if(a.include?(":"))
3232
hash = {
33-
:argumentName => a.split(":").first.strip,
34-
:argumentType => a.split(":").last.strip
33+
:argument_name => a.split(":").first.strip,
34+
:argument_type => a.split(":").last.strip
3535
}
3636
else
3737
hash = {
38-
:argumentName => a.downcase,
39-
:argumentType => a
38+
:argument_name => a.downcase,
39+
:argument_type => a
4040
}
4141
end
4242
hash
4343
end
4444
end
4545

46-
baseClass = array[0]
47-
targetClass = array[1] || baseClass
48-
targetClassName = targetClass.gsub("<", "").gsub(">", "").gsub(".", "")
46+
base_class = array[0]
47+
target_class = array[1] || base_class
48+
target_class_name = target_class.gsub("<", "").gsub(">", "").gsub(".", "")
4949
name = array[2]
5050

5151
hash = {
52-
:baseClass => baseClass,
53-
:targetClass => targetClass,
54-
:targetClassName => targetClassName,
52+
:base_class => base_class,
53+
:target_class => target_class,
54+
:target_class_name => target_class_name,
5555
:name => name,
56-
:arguments => argumentHashes
56+
:arguments => argument_hashes
5757
}
5858

59-
returnHash[:DEFINITIONS].push hash
59+
result_hash[:DEFINITIONS].push hash
6060
end
6161
end
62-
return returnHash
62+
return result_hash
6363
end
6464

6565
end

ExampleScript/example.yml

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,47 @@
22
:DEPENDENCIES:
33
- ADependency
44
:DEFINITIONS:
5-
- :baseClass: PersonType
6-
:targetClass: InjectablePerson
7-
:targetClassName: InjectablePerson
5+
- :base_class: PersonType
6+
:target_class: InjectablePerson
7+
:target_class_name: InjectablePerson
88
:name: initializer
9-
- :baseClass: PersonType
10-
:targetClass: InjectablePerson
11-
:targetClassName: InjectablePerson
12-
- :baseClass: PersonType
13-
:targetClass: PersonType
14-
:targetClassName: PersonType
15-
- :baseClass: AnotherPersonType
16-
:targetClass: AnotherPersonType
17-
:targetClassName: AnotherPersonType
18-
- :baseClass: PersonType
19-
:targetClass: InjectablePerson
20-
:targetClassName: InjectablePerson
9+
- :base_class: PersonType
10+
:target_class: InjectablePerson
11+
:target_class_name: InjectablePerson
12+
- :base_class: PersonType
13+
:target_class: PersonType
14+
:target_class_name: PersonType
15+
- :base_class: AnotherPersonType
16+
:target_class: AnotherPersonType
17+
:target_class_name: AnotherPersonType
18+
- :base_class: PersonType
19+
:target_class: InjectablePerson
20+
:target_class_name: InjectablePerson
2121
:arguments:
22-
- :argumentName: argumentName
23-
:argumentType: ArgumentType
24-
- :baseClass: PersonType
25-
:targetClass: InjectablePerson
26-
:targetClassName: InjectablePerson
22+
- :argument_name: argument_name
23+
:argument_type: argument_type
24+
- :base_class: PersonType
25+
:target_class: InjectablePerson
26+
:target_class_name: InjectablePerson
2727
:arguments:
28-
- :argumentName: argumentName
29-
:argumentType: ArgumentType
30-
- :argumentName: argumenttypewithoutspecificname
31-
:argumentType: ArgumentTypeWithoutSpecificName
32-
- :argumentName: title
33-
:argumentType: String
34-
- :argumentName: string
35-
:argumentType: String
36-
- :baseClass: PersonType
37-
:targetClass: InjectablePerson
38-
:targetClassName: InjectablePerson
28+
- :argument_name: argument_name
29+
:argument_type: argument_type
30+
- :argument_name: argument_typewithoutspecificname
31+
:argument_type: argument_typeWithoutSpecificName
32+
- :argument_name: title
33+
:argument_type: String
34+
- :argument_name: string
35+
:argument_type: String
36+
- :base_class: PersonType
37+
:target_class: InjectablePerson
38+
:target_class_name: InjectablePerson
3939
:name: initializer
4040
:arguments:
41-
- :argumentName: argumentName
42-
:argumentType: ArgumentType
43-
- :argumentName: argumenttypewithoutspecificname
44-
:argumentType: ArgumentTypeWithoutSpecificName
45-
- :argumentName: title
46-
:argumentType: String
47-
- :argumentName: string
48-
:argumentType: String
41+
- :argument_name: argument_name
42+
:argument_type: argument_type
43+
- :argument_name: argument_typewithoutspecificname
44+
:argument_type: argument_typeWithoutSpecificName
45+
- :argument_name: title
46+
:argument_type: String
47+
- :argument_name: string
48+
:argument_type: String

ExampleScript/generateCode.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#/bin/sh
22
../swinject_codegen -i example.csv -o containerExtension.swift
33
../swinject_codegen -i example.yml -o containerExtension2.swift
4-
../swinject_codegen -i example.csv -c
5-
../swinject_codegen -i example.yml -c
4+
../swinject_codegen -i example.csv -c -o example.csv.yml
5+
../swinject_codegen -i example.yml -c -o example.yml.csv
66
../swinject_codegen -i example.csv -m
77
../swinject_codegen -i example.yml -m
88
../swinject_codegen -i example.csv.yml -o containerExtension3.swift

YMLParser.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
class YMLParser
44

5-
def parseYML(inputFilename)
6-
return YAML.load_file(inputFilename)
5+
def parse_YML(input_filename)
6+
return YAML.load_file(input_filename)
77
end
88

99
end

YMLSerializer.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
class YMLSerializer
44

5-
def serializeHashToYML(hash, outputFilename)
5+
def serialize_hash_to_YML(hash, output_filename)
66
code = hash.to_yaml
77

8-
if outputFilename.nil?
8+
if output_filename.nil?
99
puts code
1010
else
11-
File.open(outputFilename, 'w') do |fileToWriteTo|
12-
fileToWriteTo.puts code
11+
File.open(output_filename, 'w') do |file_to_write_to|
12+
file_to_write_to.puts code
1313
end
1414
end
1515
end

container.erb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import <%= dependency %>
77
<% end -%>
88

99
extension Resolvable {
10-
<% @contentArray.each do |hash| %>
11-
func <%= hash[:resolveFunctionSignature] %> {
12-
return self<%= hash[:resolveFunctionCall] %><%= ", argument: #{hash[:arguments][0][:argumentName]}" if !hash[:arguments].nil? && hash[:arguments].count == 1 -%><%= ", arguments: (#{hash[:arguments].map {|a| a[:argumentName]}.join(', ')})" if !hash[:arguments].nil? && hash[:arguments].count > 1 -%>)<%=hash[:baseClass] != hash[:targetClass] ? " as! #{hash[:targetClass]}" : "!"%>
10+
<% @content_array.each do |hash| %>
11+
func <%= hash[:resolve_function_signature] %> {
12+
return self<%= hash[:resolve_function_call] %><%= ", argument: #{hash[:arguments][0][:argument_name]}" if !hash[:arguments].nil? && hash[:arguments].count == 1 -%><%= ", arguments: (#{hash[:arguments].map {|a| a[:argument_name]}.join(', ')})" if !hash[:arguments].nil? && hash[:arguments].count > 1 -%>)<%=hash[:base_class] != hash[:target_class] ? " as! #{hash[:target_class]}" : "!"%>
1313
}
1414
<% end -%>
1515
}
1616

1717
extension Container {
18-
<% @contentArray.each do |hash| %>
19-
func <%= hash[:registerFunctionSignature] %> {
20-
return self<%= hash[:registerFunctionCall] %> factory: registerClosure)
18+
<% @content_array.each do |hash| %>
19+
func <%= hash[:register_function_signature] %> {
20+
return self<%= hash[:register_function_call] %> factory: registerClosure)
2121
}
2222
<% end -%>
2323
}

csv.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<% @dependencies.uniq.each do |dependency| -%>
22
# ADD_DEPENDENCY <%= dependency %>
33
<% end -%>
4-
<% @contentArray.each do |hash| -%>
5-
<%=hash[:baseClass] unless hash[:baseClass].nil? %>; <%= hash[:targetClass] unless hash[:targetClass].nil? %> ; <%= hash[:name] unless hash[:name].nil? %> ; <%= hash[:arguments].map {|a| "#{a[:argumentName]}: #{a[:argumentType]}"}.join("; ") unless hash[:arguments].nil? %>
4+
<% @content_array.each do |hash| -%>
5+
<%=hash[:base_class] unless hash[:base_class].nil? %>; <%= hash[:target_class] unless hash[:target_class].nil? %> ; <%= hash[:name] unless hash[:name].nil? %> ; <%= hash[:arguments].map {|a| "#{a[:argument_name]}: #{a[:argument_type]}"}.join("; ") unless hash[:arguments].nil? %>
66
<% end -%>

migration.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ find . -type f | grep ".swift" > swiftindex.temp
33
while IFS= read -r filename
44
do
55
LC_ALL=C sed -i "" \
6-
<% @migrationArray.each do |hash| -%>
7-
-e s/<%=hash[:resolveFunctionCall]%>/<%=hash[:resolveFunctionSignatureRegex]%>/g \
8-
-e s/<%=hash[:registerFunctionCall]%>/<%=hash[:registerFunctionSignatureRegex]%>/g \
6+
<% @migration_array.each do |hash| -%>
7+
-e s/<%=hash[:resolve_function_call]%>/<%=hash[:resolve_function_signature_regex]%>/g \
8+
-e s/<%=hash[:register_function_call]%>/<%=hash[:register_function_signature_regex]%>/g \
99
<% end -%> "$filename"
1010
done < swiftindex.temp
1111
rm swiftindex.temp

0 commit comments

Comments
 (0)