Class: Generator::API

Inherits:
Object
  • Object
show all
Includes:
Formatter, Utils
Defined in:
lib/generator/api.rb

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

#fileObject (readonly)

Returns the value of attribute file.



18
19
20
# File 'lib/generator/api.rb', line 18

def file
  @file
end

Instance Method Details

#class_nameObject



57
58
59
# File 'lib/generator/api.rb', line 57

def class_name
  pascalcase(name_with_version)
end

#descriptionObject



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)

  split_long_comment_line(description, base_indent: 4)
end

#file_pathObject



77
78
79
# File 'lib/generator/api.rb', line 77

def file_path
  File.join(Config::BASE_PATH, "lib/#{library_name}.rb")
end

#generateObject



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

Returns:

  • (Boolean)


45
46
47
# File 'lib/generator/api.rb', line 45

def has_helper?
  File.exist?("lib/" + helper_library_name + ".rb")
end

#helper_class_nameObject



49
50
51
# File 'lib/generator/api.rb', line 49

def helper_class_name
  "Peddler::Helpers::#{pascalcase(name_with_version)}"
end

#helper_library_nameObject



53
54
55
# File 'lib/generator/api.rb', line 53

def helper_library_name
  "peddler/helpers/#{name_with_version}"
end

#library_nameObject



41
42
43
# File 'lib/generator/api.rb', line 41

def library_name
  "peddler/apis/#{name_with_version}"
end

#name_with_versionObject



61
62
63
# File 'lib/generator/api.rb', line 61

def name_with_version
  [name, version].join("_")
end

#obsolete?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/generator/api.rb', line 65

def obsolete?
  OBSOLETE_APIS.any? { |api| name_with_version.include?(api) }
end

#operationsObject



69
70
71
# File 'lib/generator/api.rb', line 69

def operations
  paths.flat_map(&:operations).compact
end

#pathsObject



73
74
75
# File 'lib/generator/api.rb', line 73

def paths
  model["paths"].map { |path, methods| Path.new(path, methods) }
end

#titleObject



30
31
32
# File 'lib/generator/api.rb', line 30

def title
  split_long_comment_line(model["info"]["title"], base_indent: 4)
end