Class: Gemkeeper::LockfileParser
- Inherits:
-
Object
- Object
- Gemkeeper::LockfileParser
- Defined in:
- lib/gemkeeper/lockfile_parser.rb
Overview
Locates the nearest Gemfile.lock by walking up; callers don’t need to know the search algorithm.
Constant Summary collapse
- LOCKFILE_NAME =
"Gemfile.lock"- VERSION_SECTION_TYPES =
%w[GEM GIT].freeze
Class Method Summary collapse
- .find(start_dir = Dir.pwd) ⇒ Object
- .internal_sources(lockfile_path) ⇒ Object
- .parse(lockfile_path) ⇒ Object
Instance Method Summary collapse
-
#gem_versions ⇒ Object
Returns name => version for all GEM and GIT section gems (excludes dependency lines).
-
#initialize(lockfile_path) ⇒ LockfileParser
constructor
A new instance of LockfileParser.
-
#internal_sources ⇒ Object
Returns an array of hashes describing gems from non-rubygems.org sources.
Constructor Details
#initialize(lockfile_path) ⇒ LockfileParser
Returns a new instance of LockfileParser.
31 32 33 |
# File 'lib/gemkeeper/lockfile_parser.rb', line 31 def initialize(lockfile_path) @lockfile_path = lockfile_path end |
Class Method Details
.find(start_dir = Dir.pwd) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/gemkeeper/lockfile_parser.rb', line 9 def self.find(start_dir = Dir.pwd) dir = File.(start_dir) loop do candidate = File.join(dir, LOCKFILE_NAME) return candidate if File.exist?(candidate) parent = File.dirname(dir) break if parent == dir dir = parent end nil end |
.internal_sources(lockfile_path) ⇒ Object
27 28 29 |
# File 'lib/gemkeeper/lockfile_parser.rb', line 27 def self.internal_sources(lockfile_path) new(lockfile_path).internal_sources end |
.parse(lockfile_path) ⇒ Object
23 24 25 |
# File 'lib/gemkeeper/lockfile_parser.rb', line 23 def self.parse(lockfile_path) new(lockfile_path).gem_versions end |
Instance Method Details
#gem_versions ⇒ Object
Returns name => version for all GEM and GIT section gems (excludes dependency lines).
36 37 38 39 40 |
# File 'lib/gemkeeper/lockfile_parser.rb', line 36 def gem_versions sections = parsed_sections sections.select { |s| VERSION_SECTION_TYPES.include?(s[:type]) } .each_with_object({}) { |section, versions| versions.merge!(versions_from_section(section)) } end |
#internal_sources ⇒ Object
Returns an array of hashes describing gems from non-rubygems.org sources. Each hash has :name, :source_type (:git or :private_gem), and either :repo (for :git) or :remote (the private gem registry URL, for :private_gem).
45 46 47 48 |
# File 'lib/gemkeeper/lockfile_parser.rb', line 45 def internal_sources sections = parsed_sections extract_git_sources(sections) + extract_private_gem_sources(sections) end |