Module: Yarnlock::Entry::Collection

Defined in:
lib/yarnlock/entry/collection.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(raw_entries) ⇒ Object



6
7
8
9
10
# File 'lib/yarnlock/entry/collection.rb', line 6

def self.parse(raw_entries)
  raw_entries.map do |pattern, raw_entry|
    Entry.parse pattern, raw_entry
  end.extend(self)
end

Instance Method Details

#as_json(_options = {}) ⇒ Object



25
26
27
28
29
# File 'lib/yarnlock/entry/collection.rb', line 25

def as_json(_options = {})
  each_with_object({}) do |entry, entries|
    entries.merge! entry.to_h
  end
end

#highest_version_packagesObject



19
20
21
22
23
# File 'lib/yarnlock/entry/collection.rb', line 19

def highest_version_packages
  each_with_object({}) do |entry, packages|
    packages[entry.package] = [entry, packages[entry.package]].compact.max_by(&:version)
  end
end

#package_with_versionsObject



12
13
14
15
16
17
# File 'lib/yarnlock/entry/collection.rb', line 12

def package_with_versions
  each_with_object({}) do |entry, packages|
    packages[entry.package] ||= {}
    packages[entry.package][entry.version] = entry
  end
end

#to_json(*options) ⇒ Object



31
32
33
# File 'lib/yarnlock/entry/collection.rb', line 31

def to_json(*options)
  as_json(*options).to_json(*options)
end