Class: Yarnlock::Entry
- Inherits:
-
Object
- Object
- Yarnlock::Entry
- Defined in:
- lib/yarnlock/entry.rb,
lib/yarnlock/entry/collection.rb
Defined Under Namespace
Modules: Collection
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#package ⇒ Object
Returns the value of attribute package.
-
#resolved ⇒ Object
Returns the value of attribute resolved.
-
#version ⇒ Object
Returns the value of attribute version.
-
#version_ranges ⇒ Object
Returns the value of attribute version_ranges.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #as_json(_options = {}) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(attributes = {}) ⇒ Entry
constructor
A new instance of Entry.
- #parse(pattern, entry) ⇒ Object
- #to_h ⇒ Object
- #to_json(*options) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Entry
Returns a new instance of Entry.
28 29 30 31 32 |
# File 'lib/yarnlock/entry.rb', line 28 def initialize(attributes = {}) attributes.each do |key, val| send "#{key}=", val end end |
Instance Attribute Details
#dependencies ⇒ Object
Returns the value of attribute dependencies.
7 8 9 |
# File 'lib/yarnlock/entry.rb', line 7 def dependencies @dependencies end |
#package ⇒ Object
Returns the value of attribute package.
7 8 9 |
# File 'lib/yarnlock/entry.rb', line 7 def package @package end |
#resolved ⇒ Object
Returns the value of attribute resolved.
7 8 9 |
# File 'lib/yarnlock/entry.rb', line 7 def resolved @resolved end |
#version ⇒ Object
Returns the value of attribute version.
8 9 10 |
# File 'lib/yarnlock/entry.rb', line 8 def version @version end |
#version_ranges ⇒ Object
Returns the value of attribute version_ranges.
7 8 9 |
# File 'lib/yarnlock/entry.rb', line 7 def version_ranges @version_ranges end |
Class Method Details
.parse(pattern, entry) ⇒ Object
10 11 12 |
# File 'lib/yarnlock/entry.rb', line 10 def self.parse(pattern, entry) new.parse pattern, entry end |
Instance Method Details
#==(other) ⇒ Object
59 60 61 |
# File 'lib/yarnlock/entry.rb', line 59 def ==(other) other.is_a?(self.class) && other.to_h == to_h end |
#as_json(_options = {}) ⇒ Object
51 52 53 |
# File 'lib/yarnlock/entry.rb', line 51 def as_json( = {}) to_h end |
#eql?(other) ⇒ Boolean
63 64 65 |
# File 'lib/yarnlock/entry.rb', line 63 def eql?(other) self == other end |
#hash ⇒ Object
67 68 69 |
# File 'lib/yarnlock/entry.rb', line 67 def hash to_h.hash end |
#parse(pattern, entry) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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 ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# 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) ⇒ Object
55 56 57 |
# File 'lib/yarnlock/entry.rb', line 55 def to_json(*) as_json(*).to_json(*) end |