Class: Generator::RBS::Unified
- Inherits:
-
Object
- Object
- Generator::RBS::Unified
- Includes:
- FileWriter, Formatter
- Defined in:
- lib/generator/rbs/unified.rb
Overview
Unified RBS generator that combines API operations and type definitions in a single file
Constant Summary
Constants included from Formatter
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#api_name ⇒ Object
readonly
Returns the value of attribute api_name.
-
#api_types ⇒ Object
readonly
Returns the value of attribute api_types.
Instance Method Summary collapse
- #class_name ⇒ Object
- #content ⇒ Object
- #generate ⇒ Object
-
#initialize(api, api_name, api_types) ⇒ Unified
constructor
A new instance of Unified.
- #operations ⇒ Object
Methods included from FileWriter
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(api, api_name, api_types) ⇒ Unified
Returns a new instance of Unified.
18 19 20 21 22 |
# File 'lib/generator/rbs/unified.rb', line 18 def initialize(api, api_name, api_types) @api = api @api_name = api_name @api_types = api_types end |
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
16 17 18 |
# File 'lib/generator/rbs/unified.rb', line 16 def api @api end |
#api_name ⇒ Object (readonly)
Returns the value of attribute api_name.
16 17 18 |
# File 'lib/generator/rbs/unified.rb', line 16 def api_name @api_name end |
#api_types ⇒ Object (readonly)
Returns the value of attribute api_types.
16 17 18 |
# File 'lib/generator/rbs/unified.rb', line 16 def api_types @api_types end |
Instance Method Details
#class_name ⇒ Object
28 29 30 |
# File 'lib/generator/rbs/unified.rb', line 28 def class_name api.class_name end |
#content ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/generator/rbs/unified.rb', line 36 def content lines = [] lines << "# #{Config::GENERATED_FILE_NOTICE}" lines << "" lines << "module Peddler" lines << " module APIs" lines << " class #{class_name} < API" # Add nested type definitions first (RBS convention) sorted_types = api_types.sort_by(&:class_name) sorted_types.each do |type| class_def = type.rbs_class_definition # Indent the class definition with 6 spaces (inside the API class) indented_class = indent(class_def, 6) lines << indented_class lines << "" # Add blank line between classes end # Add blank line between types and operations if we have both lines << "" if api_types.any? && operations.any? # Add API operations operations.each do |operation| operation_line = render_operation(operation) lines << " #{operation_line}" if operation_line end # Remove trailing blank line if present lines.pop if lines.last == "" lines << " end" lines << " end" lines << "end" lines.join("\n") + "\n" end |
#generate ⇒ Object
24 25 26 |
# File 'lib/generator/rbs/unified.rb', line 24 def generate write_file(rbs_file_path, content) end |
#operations ⇒ Object
32 33 34 |
# File 'lib/generator/rbs/unified.rb', line 32 def operations api.operations end |