Sha256: 1b5416b090e5bb136436384e666879802ba290ec91b752881b4a4c4130a9027a

Contents?: true

Size: 1.75 KB

Versions: 53

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

module Script
  module Layers
    module Domain
      class Metadata
        attr_reader :schema_major_version, :schema_minor_version, :use_msgpack

        def initialize(schema_major_version, schema_minor_version, use_msgpack)
          @schema_major_version = schema_major_version
          @schema_minor_version = schema_minor_version
          @use_msgpack = use_msgpack
        end

        class << self
          def create_from_json(ctx, metadata_json)
            err_tag = nil
            metadata_hash = JSON.parse(metadata_json)

            use_msgpack = !!metadata_hash.dig("flags", "use_msgpack")
            schema_versions = metadata_hash["schemaVersions"] || {}

            version = schema_versions.values.first || {}
            schema_major_version = version["major"]
            schema_minor_version = version["minor"]

            if schema_versions.empty?
              err_tag = "script.error.metadata_schema_versions_missing"
            elsif schema_versions.count != 1
              # Scripts may be attached to more than one EP in the future but not right now
              err_tag = "script.error.metadata_schema_versions_single_key"
            elsif schema_major_version.nil?
              err_tag = "script.error.metadata_schema_versions_missing_major"
            elsif schema_minor_version.nil?
              err_tag = "script.error.metadata_schema_versions_missing_minor"
            end

            Metadata.new(schema_major_version, schema_minor_version, use_msgpack)
          rescue JSON::ParserError
            err_tag = "script.error.metadata_validation_cause"
          ensure
            raise Errors::MetadataValidationError, ctx.message(err_tag) if err_tag
          end
        end
      end
    end
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
shopify-cli-2.2.0 lib/project_types/script/layers/domain/metadata.rb
shopify-cli-2.1.0 lib/project_types/script/layers/domain/metadata.rb
shopify-cli-2.0.2 lib/project_types/script/layers/domain/metadata.rb
shopify-cli-2.0.1 lib/project_types/script/layers/domain/metadata.rb
shopify-cli-2.0.0 lib/project_types/script/layers/domain/metadata.rb
shopify-cli-1.14.0 lib/project_types/script/layers/domain/metadata.rb
shopify-cli-1.13.1 lib/project_types/script/layers/domain/metadata.rb
shopify-cli-1.13.0 lib/project_types/script/layers/domain/metadata.rb
shopify-cli-1.12.0 lib/project_types/script/layers/domain/metadata.rb
shopify-cli-1.11.0 lib/project_types/script/layers/domain/metadata.rb
shopify-cli-1.10.0 lib/project_types/script/layers/domain/metadata.rb
shopify-cli-1.9.1 lib/project_types/script/layers/domain/metadata.rb
shopify-cli-1.9.0 lib/project_types/script/layers/domain/metadata.rb