Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.

Commit f44f937

Browse files
authored
Create mrsc.rb
0 parents  commit f44f937

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

mrsc.rb

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Helper script for creating examples used in https://tech.showmax.com/2023/01/backend-developer-guide/ blog post.
2+
#
3+
# Usage:
4+
# ruby mrsc.rb <action>
5+
#
6+
# Available actions are init, example1, example2
7+
#
8+
require 'securerandom'
9+
10+
def edit(f, r = 5, a: true)
11+
File.open(f, a ? 'a' : 'w') do |file|
12+
(rand(r) + 1).times do
13+
file.puts SecureRandom.alphanumeric(rand(16) + 1)
14+
end
15+
end
16+
end
17+
18+
def mkdir(p)
19+
Dir.mkdir(p) unless Dir.exist?(p)
20+
end
21+
22+
def del(f)
23+
File.delete(f) if File.exist?(f)
24+
end
25+
26+
def init
27+
mkdir('services')
28+
Dir.chdir('services') do
29+
3.times do |n|
30+
service = "service#{n}"
31+
mkdir(service)
32+
Dir.chdir(service) do
33+
mkdir('app')
34+
35+
edit('service_file1.rb')
36+
Dir.chdir('app') do
37+
edit('app_file1.rb')
38+
end
39+
end
40+
end
41+
end
42+
43+
mkdir('gems')
44+
Dir.chdir('gems') do
45+
mkdir('gem1')
46+
Dir.chdir('gem1') do
47+
edit('gem_file1.rb')
48+
end
49+
end
50+
end
51+
52+
def example1
53+
Dir.chdir('services/service0') do
54+
Dir.chdir('app') do
55+
edit('app_file1.rb', a: false)
56+
edit('app_file2.rb')
57+
end
58+
end
59+
Dir.chdir('services/service2') do
60+
Dir.chdir('app') do
61+
edit('app_file2.rb')
62+
end
63+
end
64+
end
65+
66+
def example2
67+
Dir.chdir('services') do
68+
3.times do |n|
69+
Dir.chdir("service#{n}") do
70+
case n
71+
when 0
72+
Dir.chdir('app') do
73+
edit('app_file1.rb', 50)
74+
edit('app_file3.rb', 50)
75+
del('app_file2.rb')
76+
end
77+
when 1
78+
Dir.chdir('app') do
79+
edit('app_file1.rb', a: false)
80+
end
81+
when 2
82+
Dir.chdir('app') do
83+
edit('app_file1.rb', 1)
84+
edit('app_file2.rb', 50)
85+
end
86+
87+
mkdir('lib')
88+
Dir.chdir('lib') do
89+
edit('lib_file1.rb', 50)
90+
end
91+
92+
edit('service_file1.rb')
93+
end
94+
end
95+
end
96+
end
97+
Dir.chdir('gems/gem1') do
98+
edit('gem_file1.rb')
99+
end
100+
end
101+
102+
case ARGV[0]
103+
when 'init'
104+
init
105+
when 'example1'
106+
example1
107+
when 'example2'
108+
example2
109+
else
110+
puts 'Missing command (init, example1, example2)'
111+
end

0 commit comments

Comments
 (0)