-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathruboty-kata.rb
More file actions
38 lines (32 loc) · 897 Bytes
/
ruboty-kata.rb
File metadata and controls
38 lines (32 loc) · 897 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
require 'open3'
require 'pathname'
module Ruboty
module Handlers
class Kata < Base
on(
/kata\s+(?<klass>\S+)(?<kind>[#.])(?<method>\S+)/,
name: 'kata',
description: "型",
)
def kata(message)
m = message.match_data
kind = m[:kind] == '#' ? '--instance' : '--singleton'
stdout, _status = Open3.capture2e('rbs', *requires, 'method', kind, m[:klass], m[:method])
message.reply <<~MARKDOWN
```
#{stdout.chomp}
```
MARKDOWN
end
private def requires
@requires ||= libraries.flat_map { |lib| ['-r', lib] }
end
private def libraries
Pathname(`gem which rbs`.chomp)
.join('../../stdlib/')
.glob('*')
.filter_map { |path| path.basename.to_s unless path.to_s.end_with?('/builtin') }
end
end
end
end