Class: Extension::Models::NpmPackage
- Inherits:
-
Object
- Object
- Extension::Models::NpmPackage
- Includes:
- Comparable, SmartProperties
- Defined in:
- lib/project_types/extension/models/npm_package.rb
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #dependency?(name) ⇒ Boolean
- #dev_dependency?(name) ⇒ Boolean
-
#initialize(**config) ⇒ NpmPackage
constructor
A new instance of NpmPackage.
- #script?(name) ⇒ Boolean
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
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
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
31 32 33 |
# File 'lib/project_types/extension/models/npm_package.rb', line 31 def script?(name) scripts.key?(name) end |