Class: Generator::API
Constant Summary
collapse
- OBSOLETE_APIS =
["reports_2020_09_04", "feeds_2020_09_04"]
Constants included
from Formatter
Formatter::MAX_LINE_LENGTH
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Utils
#pascalcase, #snakecase
Methods included from Formatter
#convert_doc_links_to_full_url, #convert_html_links_to_yard, #format_method_definition, #split_long_comment_line
Constructor Details
#initialize(file) ⇒ API
Returns a new instance of API.
20
21
22
|
# File 'lib/generator/api.rb', line 20
def initialize(file)
@file = file
end
|
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
18
19
20
|
# File 'lib/generator/api.rb', line 18
def file
@file
end
|
Instance Method Details
#class_name ⇒ Object
57
58
59
|
# File 'lib/generator/api.rb', line 57
def class_name
pascalcase(name_with_version)
end
|
#description ⇒ Object
34
35
36
37
38
39
|
# File 'lib/generator/api.rb', line 34
def description
description = model["info"]["description"]
description = convert_doc_links_to_full_url(description)
(description, base_indent: 4)
end
|
#file_path ⇒ Object
77
78
79
|
# File 'lib/generator/api.rb', line 77
def file_path
File.join(Config::BASE_PATH, "lib/#{library_name}.rb")
end
|
#generate ⇒ Object
24
25
26
27
28
|
# File 'lib/generator/api.rb', line 24
def generate
return if obsolete?
File.write(file_path, render)
end
|
#has_helper? ⇒ Boolean
45
46
47
|
# File 'lib/generator/api.rb', line 45
def has_helper?
File.exist?("lib/" + helper_library_name + ".rb")
end
|
#helper_class_name ⇒ Object
49
50
51
|
# File 'lib/generator/api.rb', line 49
def helper_class_name
"Peddler::Helpers::#{pascalcase(name_with_version)}"
end
|
#helper_library_name ⇒ Object
53
54
55
|
# File 'lib/generator/api.rb', line 53
def helper_library_name
"peddler/helpers/#{name_with_version}"
end
|
#library_name ⇒ Object
41
42
43
|
# File 'lib/generator/api.rb', line 41
def library_name
"peddler/apis/#{name_with_version}"
end
|
#name_with_version ⇒ Object
61
62
63
|
# File 'lib/generator/api.rb', line 61
def name_with_version
[name, version].join("_")
end
|
#obsolete? ⇒ Boolean
65
66
67
|
# File 'lib/generator/api.rb', line 65
def obsolete?
OBSOLETE_APIS.any? { |api| name_with_version.include?(api) }
end
|
#operations ⇒ Object
69
70
71
|
# File 'lib/generator/api.rb', line 69
def operations
paths.flat_map(&:operations).compact
end
|
#paths ⇒ Object
73
74
75
|
# File 'lib/generator/api.rb', line 73
def paths
model["paths"].map { |path, methods| Path.new(path, methods) }
end
|
#title ⇒ Object
30
31
32
|
# File 'lib/generator/api.rb', line 30
def title
(model["info"]["title"], base_indent: 4)
end
|