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



8
9
10
11
12
# File 'lib/yarnlock/entry/collection.rb', line 8

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



27
28
29
30
31
# File 'lib/yarnlock/entry/collection.rb', line 27

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

#highest_version_packagesObject



21
22
23
24
25
# File 'lib/yarnlock/entry/collection.rb', line 21

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



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

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



33
34
35
# File 'lib/yarnlock/entry/collection.rb', line 33

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