Module: Yarnlock::Entry::Collection
- Defined in:
- lib/yarnlock/entry/collection.rb
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(_options = {}) ⇒ Object
- #highest_version_packages ⇒ Object
- #package_with_versions ⇒ Object
- #to_json(*options) ⇒ Object
Class Method Details
Instance Method Details
#as_json(_options = {}) ⇒ Object
25 26 27 28 29 |
# File 'lib/yarnlock/entry/collection.rb', line 25 def as_json( = {}) each_with_object({}) do |entry, entries| entries.merge! entry.to_h end end |
#highest_version_packages ⇒ Object
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_versions ⇒ Object
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(*) as_json(*).to_json(*) end |