class Yarnlock::Entry

Attributes

dependencies[RW]
package[RW]
resolved[RW]
version[R]
version_ranges[RW]

Public Class Methods

new(attributes = {}) click to toggle source
# File lib/yarnlock/entry.rb, line 28
def initialize(attributes = {})
  attributes.each do |key, val|
    send "#{key}=", val
  end
end
parse(pattern, entry) click to toggle source
# File lib/yarnlock/entry.rb, line 10
def self.parse(pattern, entry)
  new.parse pattern, entry
end

Public Instance Methods

==(other) click to toggle source
# File lib/yarnlock/entry.rb, line 59
def ==(other)
  other.is_a?(self.class) && other.to_h == to_h
end
as_json(_options = {}) click to toggle source
# File lib/yarnlock/entry.rb, line 51
def as_json(_options = {})
  to_h
end
eql?(other) click to toggle source
# File lib/yarnlock/entry.rb, line 63
def eql?(other)
  self == other
end
hash() click to toggle source
# File lib/yarnlock/entry.rb, line 67
def hash
  to_h.hash
end
parse(pattern, entry) click to toggle source
# File lib/yarnlock/entry.rb, line 14
def parse(pattern, entry)
  self.version_ranges = []
  pattern.split(', ').each do |package_version|
    self.package, version_range = package_version.split(/(?!^)@/)
    version_ranges << version_range
  end

  self.version = entry['version']
  self.resolved = entry['resolved']
  self.dependencies = entry['dependencies']

  self
end
to_h() click to toggle source
# File lib/yarnlock/entry.rb, line 38
def to_h
  pattern = version_ranges.map do |version_range|
    "#{package}@#{version_range}"
  end.join(', ')
  {
    pattern => {
      'version' => version.to_s,
      'resolved' => resolved,
      'dependencies' => dependencies
    }.compact
  }
end
to_json(*options) click to toggle source
# File lib/yarnlock/entry.rb, line 55
def to_json(*options)
  as_json(*options).to_json(*options)
end
version=(version) click to toggle source
# File lib/yarnlock/entry.rb, line 34
def version=(version)
  @version = version.is_a?(String) ? Semantic::Version.new(version) : version
end