Class: RailsAiBridge::Registry::PackDetector
- Inherits:
-
Object
- Object
- RailsAiBridge::Registry::PackDetector
- Defined in:
- lib/rails_ai_bridge/registry/pack_detector.rb
Overview
Utility for detecting Ruby frameworks in a project's Gemfile.
Parses Gemfile content to identify the presence of Rails or Hanami gems, supporting both single and double quotes, with or without version constraints.
Class Method Summary collapse
-
.detect ⇒ Array<DetectedFramework>
Detects frameworks by checking the Gemfile in the current working directory.
-
.detect_from_content(content) ⇒ Array<DetectedFramework>
Pure function that parses Gemfile file contents to detect frameworks.
-
.detect_in_path(base_path) ⇒ Array<DetectedFramework>
Detects frameworks by checking the Gemfile in a given base directory path.
Class Method Details
.detect ⇒ Array<DetectedFramework>
Detects frameworks by checking the Gemfile in the current working directory.
34 35 36 |
# File 'lib/rails_ai_bridge/registry/pack_detector.rb', line 34 def self.detect detect_in_path('.') end |
.detect_from_content(content) ⇒ Array<DetectedFramework>
Pure function that parses Gemfile file contents to detect frameworks.
Ignores commented lines (starting with #) and matches gem declarations for 'rails' or 'hanami' with various quote styles and optional commas.
:reek:TooManyStatements -- Necessary complexity for Gemfile parsing with two framework detectors
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rails_ai_bridge/registry/pack_detector.rb', line 64 def self.detect_from_content(content) detected = [] rails_found = false hanami_found = false content.each_line do |line| trimmed = line.strip next if trimmed.start_with?('#') rails_found = detect_rails(trimmed, detected, rails_found) hanami_found = detect_hanami(trimmed, detected, hanami_found) end detected end |
.detect_in_path(base_path) ⇒ Array<DetectedFramework>
Detects frameworks by checking the Gemfile in a given base directory path.
:reek:TooManyStatements -- Necessary complexity for path validation and file reading
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rails_ai_bridge/registry/pack_detector.rb', line 43 def self.detect_in_path(base_path) clean_path = Pathname.new(base_path).cleanpath.to_s return [] if clean_path.include?('..') gemfile_path = File.join(clean_path, 'Gemfile') if File.exist?(gemfile_path) content = File.read(gemfile_path) detect_from_content(content) else [] end end |