-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
176 lines (149 loc) · 4.22 KB
/
Rakefile
File metadata and controls
176 lines (149 loc) · 4.22 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
t.verbose = true
# Load test_helper before any tests run to ensure SimpleCov starts first
t.ruby_opts << "-rtest_helper"
end
task default: :test
desc "Run tests with verbose output"
task :test_verbose do
ENV["TESTOPTS"] = "--verbose"
Rake::Task[:test].invoke
end
desc "Run a single test file"
task :test_file, [:file] do |_t, args|
ruby "test/#{args[:file]}"
end
desc "Run integration tests only"
Rake::TestTask.new(:integration) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/integration/**/*_test.rb"]
t.verbose = true
t.ruby_opts << "-rtest_helper"
end
desc "Check code style with RuboCop"
task :rubocop do
sh "bundle exec rubocop"
end
desc "Auto-correct RuboCop offenses"
task :rubocop_fix do
sh "bundle exec rubocop -a"
end
namespace :examples do
# Map of subdirectory-based demos to their entry point scripts
SUBDIR_ENTRY_POINTS = {
"14_rusty_circuit" => "open_mic.rb",
"15_memory_network_and_bus" => "editorial_pipeline.rb",
"16_writers_room" => "writers_room.rb",
"27_incident_response" => "incident_response.rb"
}.freeze
# Subdirectory demos that are standalone apps (not run via `ruby`)
STANDALONE_APPS = {
"18_rails" => { setup: "bin/setup", run: "bin/dev" }
}.freeze
desc "Run all examples (excludes standalone apps like 18_rails)"
task :all do
# Single-file examples
Dir.glob("examples/*.rb").sort.each do |example|
puts "\n#{'=' * 60}"
puts "Running: #{example}"
puts '=' * 60
ruby example
end
# Subdirectory-based demos
SUBDIR_ENTRY_POINTS.each do |dir, entry|
path = "examples/#{dir}/#{entry}"
next unless File.exist?(path)
puts "\n#{'=' * 60}"
puts "Running: #{path}"
puts '=' * 60
ruby path
end
# Remind about standalone apps
STANDALONE_APPS.each do |dir, commands|
puts "\n#{'=' * 60}"
puts "Skipped: examples/#{dir} (standalone app)"
puts " Setup: cd examples/#{dir} && #{commands[:setup]}"
puts " Run: cd examples/#{dir} && #{commands[:run]}"
puts '=' * 60
end
end
desc "Run a specific example by number (e.g., rake examples:run[1])"
task :run, [:num] do |_t, args|
padded = args[:num].rjust(2, '0')
# Try single-file example first
example = Dir.glob("examples/#{padded}_*.rb").first
if example
ruby example
next
end
# Try subdirectory-based demo
dir = Dir.glob("examples/#{padded}_*/").first
if dir
dir_name = File.basename(dir)
# Check if it's a standalone app
if STANDALONE_APPS.key?(dir_name)
commands = STANDALONE_APPS[dir_name]
puts "Example #{args[:num]} is a standalone app (#{dir_name})."
puts " Setup: cd examples/#{dir_name} && #{commands[:setup]}"
puts " Run: cd examples/#{dir_name} && #{commands[:run]}"
next
end
entry = SUBDIR_ENTRY_POINTS[dir_name]
if entry && File.exist?(File.join(dir, entry))
ruby File.join(dir, entry)
else
puts "Example #{args[:num]} directory found (#{dir_name}) but no entry point configured"
end
else
puts "Example #{args[:num]} not found"
end
end
desc "Setup the Rails demo app (example 18)"
task :rails_setup do
Dir.chdir("examples/18_rails") do
sh "bin/setup"
end
end
desc "Start the Rails demo app (example 18)"
task :rails do
Dir.chdir("examples/18_rails") do
sh "bin/dev"
end
end
end
namespace :docs do
desc "Build all documentation (YARD and MkDocs)"
task build: %i[yard mkdocs]
desc "Clean generated documentation"
task :clean do
rm_rf "doc"
rm_rf "site"
end
desc "Build YARD API documentation"
task :yard do
sh "yard doc"
end
namespace :yard do
desc "Serve YARD documentation locally"
task :serve do
sh "yard server --reload"
end
end
desc "Build MkDocs documentation"
task :mkdocs do
sh "mkdocs build"
end
namespace :mkdocs do
desc "Serve MkDocs documentation locally"
task :serve do
sh "mkdocs serve"
end
end
end