Module: RailsOpenapiGen::DebugHelpers
- Defined in:
- lib/rails-openapi-gen/debug_helpers.rb
Class Method Summary collapse
-
.analyze_file(file_path) ⇒ void
Quick analysis of a Jbuilder file.
-
.create_sample_ast ⇒ RailsOpenapiGen::AstNodes::ObjectNode
Create a sample AST tree for testing.
-
.debug_jbuilder(file_path, mode: :compact) ⇒ void
Quick debug a Jbuilder file.
-
.debug_multiple(pattern = "**/*.jbuilder", mode: :compact) ⇒ void
Debug multiple Jbuilder files at once.
-
.demo_pretty_print ⇒ void
Demo the pretty print functionality.
-
.list_examples ⇒ void
Show all available example files.
Class Method Details
.analyze_file(file_path) ⇒ void
This method returns an undefined value.
Quick analysis of a Jbuilder file
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/rails-openapi-gen/debug_helpers.rb', line 152 def self.analyze_file(file_path) unless File.exist?(file_path) puts "❌ File not found: #{file_path}" return end content = File.read(file_path) lines = content.lines puts "📊 Quick Analysis: #{File.basename(file_path)}" puts "=" * 40 puts "Lines: #{lines.size}" puts "Size: #{content.size} bytes" # Count different elements openapi_comments = lines.count { |line| line.include?('@openapi') } json_calls = lines.count { |line| line.include?('json.') } partials = lines.count { |line| line.include?('partial!') } arrays = lines.count { |line| line.include?('array!') } puts "OpenAPI comments: #{openapi_comments}" puts "JSON calls: #{json_calls}" puts "Partials: #{partials}" puts "Arrays: #{arrays}" puts "\n🔍 Preview (first 10 lines):" lines.first(10).each_with_index do |line, i| puts "#{(i + 1).to_s.rjust(2)}: #{line.chomp}" end puts "\n🚀 Parse with: RailsOpenapiGen::DebugHelpers.debug_jbuilder('#{file_path}')" end |
.create_sample_ast ⇒ RailsOpenapiGen::AstNodes::ObjectNode
Create a sample AST tree for testing
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/rails-openapi-gen/debug_helpers.rb', line 48 def self.create_sample_ast root = RailsOpenapiGen::AstNodes::ObjectNode.new( property_name: "user", comment_data: RailsOpenapiGen::AstNodes::CommentData.new( type: "object", description: "User information" ) ) # Add name property name_prop = RailsOpenapiGen::AstNodes::PropertyNode.new( property_name: "name", comment_data: RailsOpenapiGen::AstNodes::CommentData.new( type: "string", description: "User's full name", required: true ) ) root.add_child(name_prop) # Add email property email_prop = RailsOpenapiGen::AstNodes::PropertyNode.new( property_name: "email", comment_data: RailsOpenapiGen::AstNodes::CommentData.new( type: "string", description: "User's email address", required: true ) ) root.add_child(email_prop) # Add posts array posts_array = RailsOpenapiGen::AstNodes::ArrayNode.new( property_name: "posts", comment_data: RailsOpenapiGen::AstNodes::CommentData.new( type: "array", description: "User's posts" ) ) # Add post title to array items title_prop = RailsOpenapiGen::AstNodes::PropertyNode.new( property_name: "title", comment_data: RailsOpenapiGen::AstNodes::CommentData.new( type: "string", description: "Post title" ) ) posts_array.add_child(title_prop) root.add_child(posts_array) root end |
.debug_jbuilder(file_path, mode: :compact) ⇒ void
This method returns an undefined value.
Quick debug a Jbuilder file
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rails-openapi-gen/debug_helpers.rb', line 10 def self.debug_jbuilder(file_path, mode: :compact) parser = RailsOpenapiGen::Parsers::Jbuilder::JbuilderParser.new(file_path) case mode when :compact parser.debug_print_compact when :full parser.debug_print_result when :export parser.debug_export_ast else puts "Unknown mode: #{mode}. Use :compact, :full, or :export" end end |
.debug_multiple(pattern = "**/*.jbuilder", mode: :compact) ⇒ void
This method returns an undefined value.
Debug multiple Jbuilder files at once
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rails-openapi-gen/debug_helpers.rb', line 29 def self.debug_multiple(pattern = "**/*.jbuilder", mode: :compact) files = Dir.glob(pattern) if files.empty? puts "No files found with pattern: #{pattern}" return end puts "🔍 Debugging #{files.size} files with pattern: #{pattern}" puts "=" * 60 files.each_with_index do |file, index| puts "\n[#{index + 1}/#{files.size}] #{file}" debug_jbuilder(file, mode: mode) end end |
.demo_pretty_print ⇒ void
This method returns an undefined value.
Demo the pretty print functionality
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/rails-openapi-gen/debug_helpers.rb', line 105 def self.demo_pretty_print puts "🎨 Pretty Print Demo" puts "=" * 50 ast = create_sample_ast puts "\n📋 Sample AST Structure:" ast.pretty_print puts "\n📄 Debug Line Format:" puts "Root: #{ast.debug_line}" ast.children.each { |child| puts " Child: #{child.debug_line}" } puts "\n💾 Export to File:" File.open("sample_ast_debug.txt", 'w') do |f| original_stdout = $stdout $stdout = f ast.pretty_print $stdout = original_stdout end puts "Exported to: sample_ast_debug.txt" end |
.list_examples ⇒ void
This method returns an undefined value.
Show all available example files
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/rails-openapi-gen/debug_helpers.rb', line 130 def self.list_examples patterns = [ "examples/**/*.jbuilder", "spec/**/*.jbuilder", "**/*.jbuilder" ] puts "📁 Available Example Files:" puts "=" * 40 patterns.each do |pattern| files = Dir.glob(pattern) next if files.empty? puts "\n#{pattern}:" files.each { |file| puts " #{file}" } end end |