Class: Extension::Models::NpmPackage

Inherits:
Object
  • Object
show all
Includes:
Comparable, SmartProperties
Defined in:
lib/project_types/extension/models/npm_package.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**config) ⇒ NpmPackage

Returns a new instance of NpmPackage.



15
16
17
# File 'lib/project_types/extension/models/npm_package.rb', line 15

def initialize(**config)
  super(**config.select { |property_name, _| self.class.properties.key?(property_name) })
end

Class Method Details

.parse(io) ⇒ Object



19
20
21
22
23
24
# File 'lib/project_types/extension/models/npm_package.rb', line 19

def self.parse(io)
  ShopifyCLI::Result.call { JSON.parse(io.read) }
    .then(&ShopifyCLI::TransformDataStructure.new(underscore_keys: true, symbolize_keys: true, shallow: true))
    .then { |specification| new(**specification) }
    .unwrap { |error| raise "Failed to parse NPM package specification: #{error}" }
end

Instance Method Details

#<=>(other) ⇒ Object



26
27
28
29
# File 'lib/project_types/extension/models/npm_package.rb', line 26

def <=>(other)
  return nil unless name == other.name
  Semantic::Version.new(version) <=> Semantic::Version.new(other.version)
end

#dependency?(name) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/project_types/extension/models/npm_package.rb', line 35

def dependency?(name)
  dependencies.key?(name)
end

#dev_dependency?(name) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/project_types/extension/models/npm_package.rb', line 39

def dev_dependency?(name)
  dev_dependencies.key?(name)
end

#script?(name) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/project_types/extension/models/npm_package.rb', line 31

def script?(name)
  scripts.key?(name)
end