Class: Generator::Report
- Inherits:
-
Object
- Object
- Generator::Report
- Includes:
- FileWriter, SchemaGenerator, SchemaHelpers
- Defined in:
- lib/generator/report.rb
Overview
Generates Ruby type classes for SP-API report schemas from JSON Schema files
Constant Summary
Constants included from Formatter
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Class Method Summary collapse
Instance Method Summary collapse
-
#class_name ⇒ Object
Class name for the report (e.g., "EndUserData", "AccountHealth_2020_11_18").
- #generate ⇒ Object
-
#initialize(file_path) ⇒ Report
constructor
A new instance of Report.
-
#raw_description ⇒ Object
Raw description from schema (will be formatted by Type class).
-
#report_name ⇒ Object
Extract report name from filename Examples: "endUserDataReport.json" => "EndUserData" "accountHealthReport-2020-11-18.json" => "AccountHealth_2020_11_18" "b2bProductOpportunitiesNotYetOnAmazonReport-2020-11-19.json" => "B2bProductOpportunitiesNotYetOnAmazon_2020_11_19".
-
#root_properties ⇒ Object
Root properties from schema (excluding reportSpecification which is metadata).
-
#root_required_properties ⇒ Object
Required properties from root level.
Methods included from SchemaGenerator
#generate_main_file!, included, #main_template, #needs_money?, #output_file_path, #sorted_properties
Methods included from SchemaHelpers
#api_name_for_type_resolver, #attribute_name_for, #format_property_comment, #generate_nested_types!, #generate_rbs!, #generic_placeholder?, #needs_money?, #nested_type_files, #ruby_type_for, #type_resolver
Methods included from Formatter
#convert_doc_links_to_full_url, #convert_html_links_to_yard, #format_method_definition, #split_long_comment_line
Methods included from FileWriter
Constructor Details
#initialize(file_path) ⇒ Report
Returns a new instance of Report.
33 34 35 36 |
# File 'lib/generator/report.rb', line 33 def initialize(file_path) @file_path = file_path @schema = JSON.parse(File.read(file_path)) end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
25 26 27 |
# File 'lib/generator/report.rb', line 25 def file_path @file_path end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
25 26 27 |
# File 'lib/generator/report.rb', line 25 def schema @schema end |
Class Method Details
.schema_type ⇒ Object
28 29 30 |
# File 'lib/generator/report.rb', line 28 def schema_type "reports" end |
Instance Method Details
#class_name ⇒ Object
Class name for the report (e.g., "EndUserData", "AccountHealth_2020_11_18")
79 80 81 82 |
# File 'lib/generator/report.rb', line 79 def class_name # Underscore first to ensure ActiveSupport::Inflector applies acronym rules correctly report_name.underscore.camelize end |
#generate ⇒ Object
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 |
# File 'lib/generator/report.rb', line 38 def generate written_files = [] all_types = [] # Generate nested types first nested_results = generate_nested_types! written_files.concat(nested_results[:files]) all_types.concat(nested_results[:types]) # Generate main report type report_result = generate_report_type! written_files << report_result[:file] all_types << report_result[:type] # Generate main convenience file written_files << generate_main_file! # Reload to pick up newly generated files for RBS introspection IntrospectionLoader.reload written_files << generate_rbs!(all_types) # Batch format all written files format_files(written_files) Generator.logger.info("Generated #{report_name}") end |
#raw_description ⇒ Object
Raw description from schema (will be formatted by Type class)
96 97 98 99 100 101 |
# File 'lib/generator/report.rb', line 96 def raw_description return unless schema["description"] return if generic_placeholder?(schema["description"]) schema["description"] end |
#report_name ⇒ Object
Extract report name from filename Examples: "endUserDataReport.json" => "EndUserData" "accountHealthReport-2020-11-18.json" => "AccountHealth_2020_11_18" "b2bProductOpportunitiesNotYetOnAmazonReport-2020-11-19.json" => "B2bProductOpportunitiesNotYetOnAmazon_2020_11_19"
70 71 72 73 74 75 76 |
# File 'lib/generator/report.rb', line 70 def report_name base_name = File.basename(file_path, ".json") # Remove "Report" suffix name = base_name.sub(/Report$/, "") # Convert dashes to underscores for valid Ruby identifiers name.tr("-", "_") end |
#root_properties ⇒ Object
Root properties from schema (excluding reportSpecification which is metadata)
85 86 87 88 |
# File 'lib/generator/report.rb', line 85 def root_properties props = schema["properties"] || {} sorted_properties(props) end |
#root_required_properties ⇒ Object
Required properties from root level
91 92 93 |
# File 'lib/generator/report.rb', line 91 def root_required_properties schema["required"] || [] end |