Class: Generator::API
Constant Summary
Constants included
from Formatter
Formatter::MAX_LINE_LENGTH
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Logger
#logger
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.
18
19
20
|
# File 'lib/generator/api.rb', line 18
def initialize(file)
@file = file
end
|
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
16
17
18
|
# File 'lib/generator/api.rb', line 16
def file
@file
end
|
Instance Method Details
#class_name ⇒ Object
53
54
55
|
# File 'lib/generator/api.rb', line 53
def class_name
name_with_version.camelize
end
|
#description ⇒ Object
30
31
32
33
34
35
|
# File 'lib/generator/api.rb', line 30
def description
description = model["info"]["description"]
description = convert_doc_links_to_full_url(description)
(description, base_indent: 4)
end
|
#file_path ⇒ Object
87
88
89
|
# File 'lib/generator/api.rb', line 87
def file_path
File.join(Config::BASE_PATH, "lib/#{library_name}.rb")
end
|
#generate ⇒ Object
22
23
24
|
# File 'lib/generator/api.rb', line 22
def generate
File.write(file_path, render)
end
|
#github_model_filename ⇒ Object
95
96
97
|
# File 'lib/generator/api.rb', line 95
def github_model_filename
File.basename(file)
end
|
#has_helper? ⇒ Boolean
41
42
43
|
# File 'lib/generator/api.rb', line 41
def has_helper?
File.exist?("lib/" + helper_library_name + ".rb")
end
|
#helper_class_name ⇒ Object
45
46
47
|
# File 'lib/generator/api.rb', line 45
def helper_class_name
"Peddler::Helpers::#{name_with_version.camelize}"
end
|
#helper_library_name ⇒ Object
49
50
51
|
# File 'lib/generator/api.rb', line 49
def helper_library_name
"peddler/helpers/#{name_with_version}"
end
|
#library_name ⇒ Object
37
38
39
|
# File 'lib/generator/api.rb', line 37
def library_name
"peddler/apis/#{name_with_version}"
end
|
#name ⇒ Object
57
58
59
|
# File 'lib/generator/api.rb', line 57
def name
file.split("/")[-2].tr("-", "_").sub(/(?:_api)?_model$/, "")
end
|
#name_with_version ⇒ Object
65
66
67
|
# File 'lib/generator/api.rb', line 65
def name_with_version
[name, version].join("_")
end
|
#openapi_spec ⇒ Object
91
92
93
|
# File 'lib/generator/api.rb', line 91
def openapi_spec
model
end
|
#operations ⇒ Object
69
70
71
72
73
74
|
# File 'lib/generator/api.rb', line 69
def operations
@operations ||= begin
ops = paths.flat_map { |path| path.operations(name_with_version, openapi_spec) }.compact
deduplicate_operations(ops)
end
end
|
#paths ⇒ Object
83
84
85
|
# File 'lib/generator/api.rb', line 83
def paths
model["paths"].map { |path, methods| Path.new(path, methods) }
end
|
#title ⇒ Object
26
27
28
|
# File 'lib/generator/api.rb', line 26
def title
(model["info"]["title"], base_indent: 4)
end
|
#type_names ⇒ Object
76
77
78
79
80
81
|
# File 'lib/generator/api.rb', line 76
def type_names
openapi_spec["definitions"]
.select { |name, def_| def_["type"] == "object" && name != "Money" }
.keys
.sort
end
|
#version ⇒ Object
61
62
63
|
# File 'lib/generator/api.rb', line 61
def version
model["info"]["version"].tr("-", "_")
end
|