This repository was archived by the owner on Mar 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmrsc.rb
111 lines (100 loc) · 2.09 KB
/
mrsc.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
101
102
103
104
105
106
107
108
109
110
111
# Helper script for creating examples used in https://tech.showmax.com/2023/01/backend-developer-guide/ blog post.
#
# Usage:
# ruby mrsc.rb <action>
#
# Available actions are init, example1, example2
#
require 'securerandom'
def edit(f, r = 5, a: true)
File.open(f, a ? 'a' : 'w') do |file|
(rand(r) + 1).times do
file.puts SecureRandom.alphanumeric(rand(16) + 1)
end
end
end
def mkdir(p)
Dir.mkdir(p) unless Dir.exist?(p)
end
def del(f)
File.delete(f) if File.exist?(f)
end
def init
mkdir('services')
Dir.chdir('services') do
3.times do |n|
service = "service#{n}"
mkdir(service)
Dir.chdir(service) do
mkdir('app')
edit('service_file1.rb')
Dir.chdir('app') do
edit('app_file1.rb')
end
end
end
end
mkdir('gems')
Dir.chdir('gems') do
mkdir('gem1')
Dir.chdir('gem1') do
edit('gem_file1.rb')
end
end
end
def example1
Dir.chdir('services/service0') do
Dir.chdir('app') do
edit('app_file1.rb', a: false)
edit('app_file2.rb')
end
end
Dir.chdir('services/service2') do
Dir.chdir('app') do
edit('app_file2.rb')
end
end
end
def example2
Dir.chdir('services') do
3.times do |n|
Dir.chdir("service#{n}") do
case n
when 0
Dir.chdir('app') do
edit('app_file1.rb', 50)
edit('app_file3.rb', 50)
del('app_file2.rb')
end
when 1
Dir.chdir('app') do
edit('app_file1.rb', a: false)
end
when 2
Dir.chdir('app') do
edit('app_file1.rb', 1)
edit('app_file2.rb', 50)
end
mkdir('lib')
Dir.chdir('lib') do
edit('lib_file1.rb', 50)
end
edit('service_file1.rb')
end
end
end
end
Dir.chdir('gems/gem1') do
edit('gem_file1.rb')
end
end
case ARGV[0]
when 'init'
init
when 'example1'
example1
when 'example2'
example2
else
puts 'Missing command (init, example1, example2)'
end