Class: Rwm::GemfileParser
- Inherits:
-
Object
- Object
- Rwm::GemfileParser
- Defined in:
- lib/rwm/gemfile_parser.rb
Class Method Summary collapse
-
.parse(gemfile_path, known_packages) ⇒ Object
Parse a Gemfile and extract path dependencies that match known packages.
Instance Method Summary collapse
-
#initialize(gemfile_path, known_packages) ⇒ GemfileParser
constructor
A new instance of GemfileParser.
- #parse ⇒ Object
Constructor Details
#initialize(gemfile_path, known_packages) ⇒ GemfileParser
Returns a new instance of GemfileParser.
12 13 14 15 16 |
# File 'lib/rwm/gemfile_parser.rb', line 12 def initialize(gemfile_path, known_packages) @gemfile_path = gemfile_path @known_packages = known_packages @package_by_path = index_packages_by_path end |
Class Method Details
.parse(gemfile_path, known_packages) ⇒ Object
Parse a Gemfile and extract path dependencies that match known packages
8 9 10 |
# File 'lib/rwm/gemfile_parser.rb', line 8 def self.parse(gemfile_path, known_packages) new(gemfile_path, known_packages).parse end |
Instance Method Details
#parse ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rwm/gemfile_parser.rb', line 18 def parse dsl = Bundler::Dsl.new dsl.eval_gemfile(@gemfile_path) deps = dsl.dependencies gemfile_dir = File.(File.dirname(@gemfile_path)) deps.each_with_object([]) do |dep, result| source = dep.source next unless source.is_a?(Bundler::Source::Path) # Resolve the path relative to the Gemfile's directory dep_path = File.(source.path.to_s, gemfile_dir) # Skip self-references (gemspec directive points to own directory) next if dep_path == gemfile_dir matched = @package_by_path[dep_path] result << matched if matched end end |