Sha256: 0f9ffcd0de993e712f14dd6dea13fd64e4c5bf3c4c2938dd5adffe939a86e01f

Contents?: true

Size: 1.23 KB

Versions: 26

Compression:

Stored size: 1.23 KB

Contents

require "semantic/semantic"

module Extension
  module Models
    class NpmPackage
      include SmartProperties
      include Comparable

      property :name
      property :version
      property :scripts, accepts: Hash, default: -> { {} }
      property :dependencies, accepts: Hash, default: -> { {} }
      property :dev_dependencies, accepts: Hash, default: -> { {} }

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

      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

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

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

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

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

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
shopify-cli-2.36.0 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.35.0 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.34.0 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.33.1 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.33.0 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.32.1 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.32.0 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.31.0 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.30.0 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.29.0 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.28.0 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.27.0 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.26.0 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.25.0 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.24.0 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.23.0 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.22.0 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.21.0 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.20.1 lib/project_types/extension/models/npm_package.rb
shopify-cli-2.20.0 lib/project_types/extension/models/npm_package.rb