-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbloc_template.rb
100 lines (81 loc) · 2.5 KB
/
bloc_template.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
73
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
path = ARGV[0]
class_name = ARGV[1]
type = ARGV[2]
if path.nil?
puts "Please spicify the path"
return
end
if class_name.nil?
puts "Please spicify the class name"
return
end
if type.nil?
puts "Please spicify the type"
return
end
File.open("#{path}/#{class_name}State.swift", 'w') do |bloc_file|
content = <<~TEXT
import SwiftBloc
class #{class_name}State {
}
extension #{class_name}State: Equatable {
static func == (lhs: #{class_name}State, rhs: #{class_name}State) -> Bool {
<#code#>
}
}
class #{class_name}Initial: #{class_name}State {
}
TEXT
bloc_file.write content
bloc_file.close
puts "Created file: #{path}/#{class_name}State.swift"
end
if type == "bloc"
File.open("#{path}/#{class_name}Event.swift", 'w') do |bloc_file|
content = <<~TEXT
import SwiftBloc
class #{class_name}Event {
}
extension #{class_name}Event: Equatable {
static func == (lhs: #{class_name}Event, rhs: #{class_name}Event) -> Bool {
<#code#>
}
}
TEXT
bloc_file.write content
bloc_file.close
puts "Created file: #{path}/#{class_name}Event.swift"
end
File.open("#{path}/#{class_name}Bloc.swift", 'w') do |bloc_file|
content = <<~TEXT
import SwiftBloc
class #{class_name}Bloc: Bloc<#{class_name}Event, #{class_name}State> {
init() {
super.init(intialState: #{class_name}State())
}
override func mapEventToState(event: #{class_name}Event) -> #{class_name}State {
<#code#>
}
}
TEXT
bloc_file.write content
bloc_file.close
puts "Created file: #{path}/#{class_name}Bloc.swift"
end
elsif type == "cubit"
File.open("#{path}/#{class_name}Cubit.swift", 'w') do |bloc_file|
content = <<~TEXT
import SwiftBloc
class #{class_name}Cubit: Cubit<#{class_name}State> {
init() {
super.init(state: #{class_name}State())
}
}
TEXT
bloc_file.write content
bloc_file.close
puts "Created file: #{path}/#{class_name}Cubit.swift"
end
else
"Invalid type. Must be \"bloc or \"cubit"
end