Class: Yarnlock::Entry
- Inherits:
-
Object
- Object
- Yarnlock::Entry
- Defined in:
- lib/yarnlock/entry.rb,
lib/yarnlock/entry/collection.rb
Defined Under Namespace
Classes: 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
- #parse(pattern, entry) ⇒ Object
- #to_h ⇒ Object
- #to_json(*options) ⇒ Object
Instance Attribute Details
#dependencies ⇒ Object
Returns the value of attribute dependencies.
5 6 7 |
# File 'lib/yarnlock/entry.rb', line 5 def dependencies @dependencies end |
#package ⇒ Object
Returns the value of attribute package.
5 6 7 |
# File 'lib/yarnlock/entry.rb', line 5 def package @package end |
#resolved ⇒ Object
Returns the value of attribute resolved.
5 6 7 |
# File 'lib/yarnlock/entry.rb', line 5 def resolved @resolved end |
#version ⇒ Object
Returns the value of attribute version.
5 6 7 |
# File 'lib/yarnlock/entry.rb', line 5 def version @version end |
#version_ranges ⇒ Object
Returns the value of attribute version_ranges.
5 6 7 |
# File 'lib/yarnlock/entry.rb', line 5 def version_ranges @version_ranges end |
Class Method Details
.parse(pattern, entry) ⇒ Object
7 8 9 |
# File 'lib/yarnlock/entry.rb', line 7 def self.parse(pattern, entry) new.parse pattern, entry end |
Instance Method Details
#==(other) ⇒ Object
46 47 48 |
# File 'lib/yarnlock/entry.rb', line 46 def ==(other) other.is_a?(self.class) && other.to_h == to_h end |
#as_json(_options = {}) ⇒ Object
38 39 40 |
# File 'lib/yarnlock/entry.rb', line 38 def as_json( = {}) to_h end |
#parse(pattern, entry) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/yarnlock/entry.rb', line 11 def parse(pattern, entry) @version_ranges = [] pattern.split(', ').each do |package_version| @package, version_range = package_version.split(/(?!^)@/) @version_ranges << version_range end @version = entry['version'] @resolved = entry['resolved'] @dependencies = entry['dependencies'] self end |
#to_h ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/yarnlock/entry.rb', line 25 def to_h pattern = version_ranges.map do |version_range| "#{package}@#{version_range}" end.join(', ') { pattern => { 'version' => version, 'resolved' => resolved, 'dependencies' => dependencies }.reject { |_, v| v.nil? } # Hash#compact is not supported in Ruby < 2.4 } end |
#to_json(*options) ⇒ Object
42 43 44 |
# File 'lib/yarnlock/entry.rb', line 42 def to_json(*) as_json(*).to_json(*) end |