forked from goldstar/newrelic-elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
39 lines (30 loc) · 1.01 KB
/
Rakefile
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 "bundler/gem_tasks"
require "rake/testtask"
task :default => :test
task :test do
Rake::TestTask.new do |t|
t.libs << 'test'
t.pattern = "test/**/*_test.rb"
end
end
desc "Generate a new resolver class from the endpoint_list"
task :generate_resolver do
list = File.read(File.expand_path('test/endpoint_list.txt', __dir__))
pp list.lines.each.with_object({}) { |l, memo|
scanner = StringScanner.new(l)
scanner.scan_until(/(POST|GET|PUT|DELETE|HEAD)/)
next if scanner.pre_match.nil?
operation_name = scanner.pre_match.rstrip
method = scanner.matched
url_pattern = scanner.rest
api_name = if matches = /\/(_.*?)(\/|\b)/.match(url_pattern)
matches[1]
end
if memo.has_key?([method, api_name])
next if memo[[method, api_name]] == operation_name
memo[[method, api_name]] = :"ambiguous#{api_name || "_" + method.downcase}_resolver"
else
memo[[method, api_name]] = operation_name
end
}.sort_by { |k,v| k[1] || '_' }.to_h
end