Module: Aidp::Analysis::Seams
- Defined in:
- lib/aidp/analysis/seams.rb
Constant Summary collapse
- IO_PATTERNS =
I/O and OS integration patterns
[ /^File\./, /^IO\./, /^Kernel\.system$/, /^Open3\./, /^Net::HTTP/, /Socket|TCPSocket|UDPSocket/, /^Dir\./, /^ENV/, /^ARGV/, /^STDIN|^STDOUT|^STDERR/, /^Process\./, /^Thread\./, /^Timeout\./ ].freeze
- EXTERNAL_SERVICE_PATTERNS =
Database and external service patterns
[ /ActiveRecord|Sequel|DataMapper/, /Redis|Memcached/, /Elasticsearch/, /AWS::|Google::|Azure::/, /HTTParty|Faraday|Net::HTTP/, /Sidekiq|Resque|DelayedJob/, /ActionMailer|Mail/ ].freeze
- GLOBAL_PATTERNS =
Global and singleton patterns
[ /^\$[a-zA-Z_]/, /^@@[a-zA-Z_]/, /^::[A-Z]/, /^Kernel\./, /include Singleton/, /extend Singleton/, /@singleton/ ].freeze
Class Method Summary collapse
- .detect_class_module_seams(class_node, file_path) ⇒ Object
- .detect_method_seams(method_node, file_path) ⇒ Object
- .detect_seams_in_ast(ast_nodes, file_path) ⇒ Object
Class Method Details
.detect_class_module_seams(class_node, file_path) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/aidp/analysis/seams.rb', line 99 def self.detect_class_module_seams(class_node, file_path) seams = [] # Check for singleton pattern if class_node[:content]&.include?("include Singleton") seams << { kind: "singleton_pattern", file: file_path, line: class_node[:line], symbol_id: "#{file_path}:#{class_node[:line]}:#{class_node[:name]}", detail: { pattern: "Singleton", class_name: class_node[:name] }, suggestion: "Consider using dependency injection instead of singleton pattern" } end # Check for global state in class/module if (global_state = extract_global_state(class_node)) global_state.each do |state| seams << { kind: "global_state", file: file_path, line: state[:line], symbol_id: "#{file_path}:#{class_node[:line]}:#{class_node[:name]}", detail: { state: state[:state], type: state[:type] }, suggestion: "Consider encapsulating global state or using configuration objects" } end end seams end |
.detect_method_seams(method_node, file_path) ⇒ Object
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 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 |
# File 'lib/aidp/analysis/seams.rb', line 41 def self.detect_method_seams(method_node, file_path) seams = [] # Check for I/O calls in method body if (io_calls = extract_io_calls(method_node)) io_calls.each do |call| seams << { kind: "io_integration", file: file_path, line: call[:line], symbol_id: "#{file_path}:#{method_node[:line]}:#{method_node[:name]}", detail: { call: call[:call], receiver: call[:receiver], method: call[:method] }, suggestion: "Consider extracting I/O operations to a separate service class" } end end # Check for external service calls if (service_calls = extract_external_service_calls(method_node)) service_calls.each do |call| seams << { kind: "external_service", file: file_path, line: call[:line], symbol_id: "#{file_path}:#{method_node[:line]}:#{method_node[:name]}", detail: { call: call[:call], service: call[:service] }, suggestion: "Consider using dependency injection for external service calls" } end end # Check for global/singleton usage if (global_usage = extract_global_usage(method_node)) global_usage.each do |usage| seams << { kind: "global_singleton", file: file_path, line: usage[:line], symbol_id: "#{file_path}:#{method_node[:line]}:#{method_node[:name]}", detail: { usage: usage[:usage], type: usage[:type] }, suggestion: "Consider passing global state as parameters or using dependency injection" } end end seams end |
.detect_seams_in_ast(ast_nodes, file_path) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/aidp/analysis/seams.rb', line 26 def self.detect_seams_in_ast(ast_nodes, file_path) seams = [] ast_nodes.each do |node| case node[:type] when "method" seams.concat(detect_method_seams(node, file_path)) when "class", "module" seams.concat(detect_class_module_seams(node, file_path)) end end seams end |