Skip to content

Commit 5925c69

Browse files
committed
[API] Code Generator: Refactors FilesHelper
1 parent c8ede6c commit 5925c69

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

elasticsearch-api/utils/thor/generator/files_helper.rb

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,40 @@ module Elasticsearch
2222
module API
2323
# Helper with file related methods for code generation
2424
module FilesHelper
25+
2526
PROJECT_PATH = File.join(File.dirname(__FILE__), '..')
2627
SRC_PATH = File.join(PROJECT_PATH, '..', '..', '..', 'tmp/rest-api-spec/api/')
2728
OUTPUT_DIR = '../../elasticsearch-api/lib/elasticsearch/api/actions'.freeze
2829
TESTS_DIRECTORY = "#{PROJECT_PATH}/../../../tmp/rest-api-spec/test/free".freeze
2930

30-
# Only get JSON files and remove hidden files
31-
def self.files
32-
json_files = Dir.entries(SRC_PATH)
31+
class << self
32+
# Only get JSON files and remove hidden files
33+
def files
34+
json_files = Dir.entries(SRC_PATH)
3335

34-
json_files.reject do |file|
35-
File.extname(file) != '.json' ||
36-
File.basename(file) == '_common.json'
37-
end.map { |file| "#{SRC_PATH}#{file}" }
38-
end
36+
json_files.reject do |file|
37+
File.extname(file) != '.json' ||
38+
File.basename(file) == '_common.json'
39+
end.map { |file| "#{SRC_PATH}#{file}" }
40+
end
3941

40-
# Path to directory to copy generated files
41-
def self.output_dir
42-
Pathname(OUTPUT_DIR)
43-
end
42+
# Path to directory to copy generated files
43+
def output_dir
44+
Pathname(OUTPUT_DIR)
45+
end
4446

45-
def self.documentation_url(documentation_url)
46-
branch = `git rev-parse --abbrev-ref HEAD`
47-
return documentation_url.gsub(/\/(master|main)\//, "/current/") if branch == "main\n"
47+
def documentation_url(documentation_url)
48+
branch = `git rev-parse --abbrev-ref HEAD`
49+
return documentation_url.gsub(/\/(master|main)\//, "/current/") if branch == "main\n"
4850

49-
regex = /([0-9]{1,2}\.[0-9x]{1,2})/
50-
version = Elasticsearch::API::VERSION.match(regex)[0]
51-
# TODO - How do we fix this so it doesn't depend on which branch we're running from
52-
if ENV['IGNORE_VERSION']
53-
documentation_url.gsub(/\/(master|main)\//, "/current/")
54-
else
55-
documentation_url.gsub(/\/(current|master|main)\//, "/#{version}/")
51+
regex = /([0-9]{1,2}\.[0-9x]{1,2})/
52+
version = Elasticsearch::API::VERSION.match(regex)[0]
53+
# TODO - How do we fix this so it doesn't depend on which branch we're running from
54+
if ENV['IGNORE_VERSION']
55+
documentation_url.gsub(/\/(master|main)\//, "/current/")
56+
else
57+
documentation_url.gsub(/\/(current|master|main)\//, "/#{version}/")
58+
end
5659
end
5760
end
5861

0 commit comments

Comments
 (0)