Class: LibyearRb::LockfileParser
- Inherits:
-
Object
- Object
- LibyearRb::LockfileParser
- Defined in:
- lib/libyear_rb/lockfile_parser.rb
Constant Summary collapse
- BUNDLED_WITH =
Section markers
/^BUNDLED WITH$/- CHECKSUMS =
/^CHECKSUMS$/- DEPENDENCIES =
/^DEPENDENCIES$/- GEM =
/^GEM$/- GIT =
/^GIT$/- PATH =
/^PATH$/- PLATFORMS =
/^PLATFORMS$/- PLUGIN =
/^PLUGIN SOURCE$/- RUBY =
/^RUBY VERSION$/- REMOTE =
Entry patterns
/^ remote: (.+)$/- REVISION =
/^ revision: (.+)$/- SPECS =
/^ specs:$/- OPTION =
/^ ([a-z]+): (.+)$/i- SPEC_ENTRY =
/^ ([^ (]+)(?: \(([^)]+)\))?$/- DEPENDENCY_ENTRY =
/^ ([^ (]+)(?: \(([^)]+)\))?$/- TOP_LEVEL_DEPENDENCY =
/^ ([^ (]+)(?: \(([^)]+)\))?(!)?$/- PLATFORM_ENTRY =
/^ (.+)$/- VERSION_LINE =
/^ ?([^ ].+)$/- BUNDLED_VERSION =
/^ ?([^ ].+)$/
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.parse(lockfile_content) ⇒ Object
28 29 30 |
# File 'lib/libyear_rb/lockfile_parser.rb', line 28 def self.parse(lockfile_content) new.parse(lockfile_content) end |
Instance Method Details
#parse(lockfile_content) ⇒ Object
32 33 34 35 36 37 38 39 40 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 |
# File 'lib/libyear_rb/lockfile_parser.rb', line 32 def parse(lockfile_content) lines = lockfile_content.lines(chomp: true) sources = [] platforms = [] dependencies = [] ruby_version = nil bundled_with = nil i = 0 while i < lines.length line = lines[i] case line when GIT, GEM, PATH, PLUGIN source, next_i = parse_source(lines, i) sources << source i = next_i when PLATFORMS platforms, i = parse_platforms(lines, i + 1) when DEPENDENCIES dependencies, i = parse_dependencies(lines, i + 1) when RUBY ruby_version, i = parse_ruby_version(lines, i + 1) when BUNDLED_WITH bundled_with, i = parse_bundled_with(lines, i + 1) when CHECKSUMS i = skip_section(lines, i + 1) else i += 1 end end direct_names = dependencies.map(&:name) sources = sources.map do |source| source.with(specs: source.specs.map { |spec| spec.with(direct: direct_names.include?(spec.name)) }) end Lockfile.new( sources: sources, platforms: platforms, dependencies: dependencies, ruby_version: ruby_version, bundled_with: bundled_with ) end |