Class: Generator::Feed
- Inherits:
-
Object
- Object
- Generator::Feed
- Includes:
- FileWriter, SchemaGenerator, SchemaHelpers
- Defined in:
- lib/generator/feed.rb
Overview
Generates Ruby type classes for SP-API feed schemas from JSON Schema files
Constant Summary
Constants included from Formatter
Generator::Formatter::MAX_LINE_LENGTH
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
-
.filter_schema_files(files) ⇒ Object
Override to filter out example files.
- .schema_type ⇒ Object
Instance Method Summary collapse
-
#class_name ⇒ Object
Class name for the feed (e.g., "ListingsFeedSchema").
-
#feed_name ⇒ Object
Extract feed name from filename Examples: "listings-feed-schema-v2.json" => "ListingsFeedSchema" "listings-feed-message-schema-v2.json" => "ListingsFeedMessageSchema" "listings-feed-processing-report-schema-v2.json" => "ListingsFeedProcessingReportSchema".
- #generate ⇒ Object
-
#initialize(file_path) ⇒ Feed
constructor
A new instance of Feed.
-
#raw_description ⇒ Object
Class description from schema Raw description from schema (will be formatted by Type class).
-
#root_properties ⇒ Object
Root properties from schema.
-
#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) ⇒ Feed
Returns a new instance of Feed.
38 39 40 41 |
# File 'lib/generator/feed.rb', line 38 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/feed.rb', line 25 def file_path @file_path end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
25 26 27 |
# File 'lib/generator/feed.rb', line 25 def schema @schema end |
Class Method Details
.filter_schema_files(files) ⇒ Object
Override to filter out example files
33 34 35 |
# File 'lib/generator/feed.rb', line 33 def filter_schema_files(files) files.reject { |file| file.include?(".example.") } end |
.schema_type ⇒ Object
28 29 30 |
# File 'lib/generator/feed.rb', line 28 def schema_type "feeds" end |
Instance Method Details
#class_name ⇒ Object
Class name for the feed (e.g., "ListingsFeedSchema")
84 85 86 87 |
# File 'lib/generator/feed.rb', line 84 def class_name # Underscore first to ensure ActiveSupport::Inflector applies acronym rules correctly feed_name.underscore.camelize end |
#feed_name ⇒ Object
Extract feed name from filename Examples: "listings-feed-schema-v2.json" => "ListingsFeedSchema" "listings-feed-message-schema-v2.json" => "ListingsFeedMessageSchema" "listings-feed-processing-report-schema-v2.json" => "ListingsFeedProcessingReportSchema"
75 76 77 78 79 80 81 |
# File 'lib/generator/feed.rb', line 75 def feed_name base_name = File.basename(file_path, ".json") # Remove version suffix (e.g., "-v2") name = base_name.sub(/-v\d+$/, "") # Convert to PascalCase, treating "feed" and "schema" as separate words name.split("-").map(&:capitalize).join end |
#generate ⇒ Object
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 |
# File 'lib/generator/feed.rb', line 43 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 feed type feed_result = generate_feed_type! written_files << feed_result[:file] all_types << feed_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 #{feed_name}") end |
#raw_description ⇒ Object
Class description from schema Raw description from schema (will be formatted by Type class)
102 103 104 105 106 107 108 109 |
# File 'lib/generator/feed.rb', line 102 def raw_description return unless schema["title"] || schema["description"] description = schema["title"] || schema["description"] return if generic_placeholder?(description) description end |
#root_properties ⇒ Object
Root properties from schema
90 91 92 93 |
# File 'lib/generator/feed.rb', line 90 def root_properties props = schema["properties"] || {} sorted_properties(props) end |
#root_required_properties ⇒ Object
Required properties from root level
96 97 98 |
# File 'lib/generator/feed.rb', line 96 def root_required_properties schema["required"] || [] end |