Class: Yarnlock::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/yarnlock/entry.rb,
lib/yarnlock/entry/collection.rb

Defined Under Namespace

Modules: Collection

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dependenciesObject

Returns the value of attribute dependencies.



7
8
9
# File 'lib/yarnlock/entry.rb', line 7

def dependencies
  @dependencies
end

#packageObject

Returns the value of attribute package.



7
8
9
# File 'lib/yarnlock/entry.rb', line 7

def package
  @package
end

#resolvedObject

Returns the value of attribute resolved.



7
8
9
# File 'lib/yarnlock/entry.rb', line 7

def resolved
  @resolved
end

#versionObject

Returns the value of attribute version.



7
8
9
# File 'lib/yarnlock/entry.rb', line 7

def version
  @version
end

#version_rangesObject

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



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

def self.parse(pattern, entry)
  new.parse pattern, entry
end

Instance Method Details

#==(other) ⇒ Object



48
49
50
# File 'lib/yarnlock/entry.rb', line 48

def ==(other)
  other.is_a?(self.class) && other.to_h == to_h
end

#as_json(_options = {}) ⇒ Object



40
41
42
# File 'lib/yarnlock/entry.rb', line 40

def as_json(_options = {})
  to_h
end

#parse(pattern, entry) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/yarnlock/entry.rb', line 13

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'].to_version
  @resolved = entry['resolved']
  @dependencies = entry['dependencies']

  self
end

#to_hObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/yarnlock/entry.rb', line 27

def to_h
  pattern = version_ranges.map do |version_range|
    "#{package}@#{version_range}"
  end.join(', ')
  {
    pattern => {
      'version' => version.to_s,
      'resolved' => resolved,
      'dependencies' => dependencies
    }.reject { |_, v| v.nil? } # Hash#compact is not supported in Ruby < 2.4
  }
end

#to_json(*options) ⇒ Object



44
45
46
# File 'lib/yarnlock/entry.rb', line 44

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