-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuardfile
More file actions
40 lines (35 loc) · 749 Bytes
/
Guardfile
File metadata and controls
40 lines (35 loc) · 749 Bytes
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
class AdventMatcher
def initialize(suffix)
@glob = %r{\d+/[^/]+\.#{suffix}}
end
def match(path)
path = path.to_s
return nil unless path&.match?(@glob)
year, lang, _file = path.split("/")
return nil unless /\d{4}/.match?(year)
{
script: path
}
end
end
require "./lib/runner"
require "benchmark"
def watch_for(suffix, runner)
watch(AdventMatcher.new(suffix)) do |match|
path = match[:script]
puts ">> #{path}"
bm = Benchmark.measure do
puts runner.new(path).build.execute!
end
puts bm
puts
end
end
watch %r{lib/[^/]*\.rb} do
Guard.reload
end
guard :shell do
watch_for("exs?", ::Runner::Elixir)
watch_for("nim", ::Runner::Nim)
watch_for("rb", ::Runner::Ruby)
end