Skip to content

Commit d824949

Browse files
committed
ruby script to create bloc files
1 parent c20e66a commit d824949

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

bloc_template.rb

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
path = ARGV[0]
2+
class_name = ARGV[1]
3+
type = ARGV[2]
4+
5+
if path.nil?
6+
puts "Please spicify the path"
7+
return
8+
end
9+
10+
if class_name.nil?
11+
puts "Please spicify the class name"
12+
return
13+
end
14+
15+
if type.nil?
16+
puts "Please spicify the type"
17+
return
18+
end
19+
20+
File.open("#{path}/#{class_name}State.swift", 'w') do |bloc_file|
21+
content = <<~TEXT
22+
import SwiftBloc
23+
24+
class #{class_name}State {
25+
26+
}
27+
28+
extension #{class_name}State: Equatable {
29+
static func == (lhs: #{class_name}State, rhs: #{class_name}State) -> Bool {
30+
<#code#>
31+
}
32+
}
33+
34+
class #{class_name}Initial: #{class_name}State {
35+
36+
}
37+
TEXT
38+
39+
bloc_file.write content
40+
bloc_file.close
41+
puts "Created file: #{path}/#{class_name}State.swift"
42+
end
43+
if type == "bloc"
44+
File.open("#{path}/#{class_name}Event.swift", 'w') do |bloc_file|
45+
content = <<~TEXT
46+
import SwiftBloc
47+
48+
class #{class_name}Event {
49+
50+
}
51+
52+
extension #{class_name}Event: Equatable {
53+
static func == (lhs: #{class_name}Event, rhs: #{class_name}Event) -> Bool {
54+
<#code#>
55+
}
56+
}
57+
TEXT
58+
59+
bloc_file.write content
60+
bloc_file.close
61+
puts "Created file: #{path}/#{class_name}Event.swift"
62+
end
63+
File.open("#{path}/#{class_name}Bloc.swift", 'w') do |bloc_file|
64+
content = <<~TEXT
65+
import SwiftBloc
66+
67+
class #{class_name}Bloc: Bloc<#{class_name}Event, #{class_name}State> {
68+
init() {
69+
super.init(intialState: #{class_name}State())
70+
}
71+
72+
override func mapEventToState(event: #{class_name}Event) -> #{class_name}State {
73+
<#code#>
74+
}
75+
}
76+
TEXT
77+
78+
bloc_file.write content
79+
bloc_file.close
80+
puts "Created file: #{path}/#{class_name}Bloc.swift"
81+
end
82+
elsif type == "cubit"
83+
File.open("#{path}/#{class_name}Cubit.swift", 'w') do |bloc_file|
84+
content = <<~TEXT
85+
import SwiftBloc
86+
87+
class #{class_name}Cubit: Cubit<#{class_name}State> {
88+
init() {
89+
super.init(state: #{class_name}State())
90+
}
91+
}
92+
TEXT
93+
94+
bloc_file.write content
95+
bloc_file.close
96+
puts "Created file: #{path}/#{class_name}Cubit.swift"
97+
end
98+
else
99+
"Invalid type. Must be \"bloc or \"cubit"
100+
end

0 commit comments

Comments
 (0)