Skip to content

Commit 62bd2e3

Browse files
committed
woop woop
1 parent e4c89d7 commit 62bd2e3

3 files changed

Lines changed: 18 additions & 20 deletions

File tree

lib/cli.rb

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ def validate_args
5656
end
5757
end
5858

59-
cli = Cli.new(ARGV)
59+
Cli.new(ARGV)

lib/code_generation.rb

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ def initialize(opts = {})
2929
end
3030

3131
# camel cased name
32-
def name
33-
@name
34-
end
32+
attr_reader :name
3533

3634
def class_name
3735
"CGameController#{@name}"
@@ -64,7 +62,7 @@ def self.pvp
6462
@@pvp_controller = Controller.new(
6563
path: ['base_pvp'],
6664
name: 'pvp',
67-
filename: 'base_pvp',
65+
filename: 'base_pvp'
6866
)
6967
end
7068

@@ -73,7 +71,7 @@ def self.pvp
7371
def self.list
7472
{
7573
pvp: {
76-
controller: self.pvp,
74+
controller: pvp,
7775
description: 'Basic pvp controller. Top recommendation!'
7876
}
7977
}
@@ -92,6 +90,7 @@ class FileSystemHelper
9290
# @param text [String] text to be written to file
9391
def write(path, text)
9492
return unless ok_to_overwrite? path
93+
9594
File.write(path, text)
9695
end
9796

@@ -100,7 +99,7 @@ def ok_to_overwrite?(path)
10099

101100
puts "[!] the following file already exists #{path}"
102101
puts "[!] do you really want to overwrite it? (y/N)"
103-
return true if $stdin.gets.chomp.match? /[Yy](es)?/
102+
return true if $stdin.gets.chomp.match?(/[Yy](es)?/)
104103

105104
puts "[!] skipping file ..."
106105
false
@@ -199,7 +198,7 @@ def constructor_body
199198
"m_pStatsTable = \"#{@controller.name_snake}\";",
200199
"m_pExtraColumns = nullptr; // new C#{@controller.name}Columns();",
201200
"m_pSqlStats->SetExtraColumns(m_pExtraColumns);",
202-
"m_pSqlStats->CreateTable(m_pStatsTable);",
201+
"m_pSqlStats->CreateTable(m_pStatsTable);"
203202
].map { |m| "\t#{m}" }.join("\n")
204203
end
205204

@@ -209,15 +208,14 @@ def include_guard_open
209208
slug += @controller.name.to_snake.upcase
210209
[
211210
"#ifndef GAME_SERVER_GAMEMODES_#{slug}_H",
212-
"#define GAME_SERVER_GAMEMODES_#{slug}_H",
211+
"#define GAME_SERVER_GAMEMODES_#{slug}_H"
213212
].join("\n")
214213
end
215214

216215
def include_guard_close
217216
"#endif"
218217
end
219218

220-
221219
def source_methods
222220
# TODO: the header and source methods should be be kept in sync with some kind of data structure
223221
# that matches methods by name
@@ -230,16 +228,16 @@ def source_methods
230228
"void #{@controller.class_name}::OnInit()",
231229
empty_method_body("void"),
232230
"int #{@controller.class_name}::OnCharacterDeath(CCharacter *pVictim, class CPlayer *pKiller, int Weapon)",
233-
empty_method_body("int"),
231+
empty_method_body("int")
234232
].join("\n")
235233
end
236234

237235
def empty_method_body(return_type)
238236
lines = ["{"]
239237
case return_type
240-
when "void" then nil
241-
when "int" then lines << " return 0;"
242-
else raise "Unknown return type: #{return_type}"
238+
when "void" then nil
239+
when "int" then lines << " return 0;"
240+
else raise "Unknown return type: #{return_type}"
243241
end
244242
lines << "}"
245243
lines << ""
@@ -249,7 +247,7 @@ def empty_method_body(return_type)
249247
def header_methods
250248
[
251249
"void OnInit() override;",
252-
"int OnCharacterDeath(class CCharacter *pVictim, CPlayer *pKiller, int Weapon) override;",
250+
"int OnCharacterDeath(class CCharacter *pVictim, CPlayer *pKiller, int Weapon) override;"
253251
].map { |m| "\t#{m}" }.join("\n")
254252
end
255253
end

lib/strings.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
class String
22
def snake_to_camel
3-
self.split('_').map { |w| w.capitalize }.join
3+
split('_').map(&:capitalize).join
44
end
55

66
def camel_to_snake
7-
self.split(/([A-Z][a-z]*)/).each_slice(2).map(&:join).map(&:downcase).join('_')
7+
split(/([A-Z][a-z]*)/).each_slice(2).map(&:join).map(&:downcase).join('_')
88
end
99

1010
def to_camel
11-
return snake_to_camel if self.match? /_/
12-
return self.capitalize if self.downcase == self
11+
return snake_to_camel if match?(/_/)
12+
return capitalize if downcase == self
1313

1414
self
1515
end
1616

1717
def to_snake
18-
return self if self.match? /_/
18+
return self if match?(/_/)
1919

2020
camel_to_snake
2121
end

0 commit comments

Comments
 (0)