Class: Gurney::Source::Yarn

Inherits:
Base
  • Object
show all
Defined in:
lib/gurney/source/yarn.rb

Constant Summary collapse

YARN_LOCK_REGEX =
/^"?(?<name>\S*)@.+?"?:\n\s{2}version "(?<version>.+?)"$/m

Instance Method Summary collapse

Constructor Details

#initialize(yarn_lock:) ⇒ Yarn

Returns a new instance of Yarn.



7
8
9
# File 'lib/gurney/source/yarn.rb', line 7

def initialize(yarn_lock:)
  @yarn_lock = yarn_lock
end

Instance Method Details

#dependenciesObject



15
16
17
18
19
20
# File 'lib/gurney/source/yarn.rb', line 15

def dependencies
  if present?
    dependencies = @yarn_lock.scan(YARN_LOCK_REGEX).map{|match| { name: match[0], version: match[1] } }
    dependencies.map { |dependency| Dependency.new(ecosystem: 'npm', **dependency) }
  end
end

#present?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/gurney/source/yarn.rb', line 11

def present?
  !@yarn_lock.nil?
end