Module: Generator::SchemaGenerator
- Included in:
- Feed, Notification, Report
- Defined in:
- lib/generator/support/schema_generator.rb
Overview
Shared functionality for schema-based generators (Notification, Report, Feed) Provides common patterns for file discovery, cleanup, and generation
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#generate_main_file! ⇒ Object
Generate main convenience file using ERB template.
-
#main_template ⇒ Object
Get main template content.
-
#needs_money? ⇒ Boolean
Check if any types use Money (shared implementation).
-
#output_file_path ⇒ Object
Get output file path for main file.
-
#sorted_properties(props) ⇒ Object
Sort properties (natural alphabetical order by default) Can be overridden for custom sorting.
Class Method Details
.included(base) ⇒ Object
10 11 12 |
# File 'lib/generator/support/schema_generator.rb', line 10 def included(base) base.extend(ClassMethods) end |
Instance Method Details
#generate_main_file! ⇒ Object
Generate main convenience file using ERB template
58 59 60 61 |
# File 'lib/generator/support/schema_generator.rb', line 58 def generate_main_file! content = ERB.new(main_template, trim_mode: "-").result(binding) write_file(output_file_path, content) end |
#main_template ⇒ Object
Get main template content
70 71 72 73 |
# File 'lib/generator/support/schema_generator.rb', line 70 def main_template template_name = self.class.name.split("::").last.underscore File.read(Config.template_path(template_name)) end |
#needs_money? ⇒ Boolean
Check if any types use Money (shared implementation)
86 87 88 89 90 |
# File 'lib/generator/support/schema_generator.rb', line 86 def needs_money? extractor = JsonSchemaExtractor.new(schema, send(:name)) extracted_types = extractor.extract_types super(extracted_types) end |
#output_file_path ⇒ Object
Get output file path for main file
76 77 78 79 80 81 82 83 |
# File 'lib/generator/support/schema_generator.rb', line 76 def output_file_path schema_name_method = "#{self.class.schema_type.singularize}_name" schema_name = send(schema_name_method) File.join( Config::BASE_PATH, "lib/peddler/#{self.class.schema_type}/#{schema_name.underscore}.rb", ) end |
#sorted_properties(props) ⇒ Object
Sort properties (natural alphabetical order by default) Can be overridden for custom sorting
65 66 67 |
# File 'lib/generator/support/schema_generator.rb', line 65 def sorted_properties(props) props.sort.to_h end |