cocina-models 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/cocina/models.rb +5 -0
- data/lib/cocina/models/admin_policy.rb +6 -19
- data/lib/cocina/models/catalog_link.rb +1 -9
- data/lib/cocina/models/collection.rb +6 -26
- data/lib/cocina/models/description.rb +2 -14
- data/lib/cocina/models/dro.rb +6 -35
- data/lib/cocina/models/file.rb +8 -59
- data/lib/cocina/models/file_set.rb +4 -24
- data/lib/cocina/models/release_tag.rb +2 -6
- data/lib/cocina/models/request_admin_policy.rb +2 -2
- data/lib/cocina/models/request_collection.rb +2 -2
- data/lib/cocina/models/request_dro.rb +2 -2
- data/lib/cocina/models/version.rb +1 -1
- metadata +2 -5
- data/lib/cocina/models/admin_policy_builder.rb +0 -30
- data/lib/cocina/models/collection_builder.rb +0 -35
- data/lib/cocina/models/dro_builder.rb +0 -31
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: db9943bd397ca96d689ba22f2d9b5f47167d24c1a00ebe140129189bc2ac870c
         | 
| 4 | 
            +
              data.tar.gz: cb1842b31d65dab3f9bf49f7ea9c228e1af92e50cbb3b4e9143d444210f26509
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e104cabd5dc7d865028e13b90bc4646cc25d9a5b2a297156f4452f28c245bf66a9b864fe39fa8a00455f1d00063c3a780b6d5c7ff9ed40d95462a819a7c22171
         | 
| 7 | 
            +
              data.tar.gz: a9d176f0df5c1f80a0532c0877973539e4550967eda88d7b0a0fab4d74db413692f58822d8a15037bb672dd3c53b8808707d2349aedf908d108a14de574ca11c
         | 
    
        data/lib/cocina/models.rb
    CHANGED
    
    | @@ -36,6 +36,11 @@ module Cocina | |
| 36 36 | 
             
                # Raised when the type attribute is not valid.
         | 
| 37 37 | 
             
                class UnknownTypeError < Error; end
         | 
| 38 38 |  | 
| 39 | 
            +
                # Base class for Cocina Structs
         | 
| 40 | 
            +
                class Struct < Dry::Struct
         | 
| 41 | 
            +
                  transform_keys(&:to_sym)
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 39 44 | 
             
                # @param [Hash] dyn a ruby hash representation of the JSON serialization of a collection or DRO
         | 
| 40 45 | 
             
                # @return [DRO,Collection]
         | 
| 41 46 | 
             
                # @raises [UnknownTypeError] if a valid type is not found in the data
         | 
| @@ -3,7 +3,7 @@ | |
| 3 3 | 
             
            module Cocina
         | 
| 4 4 | 
             
              module Models
         | 
| 5 5 | 
             
                # An admin policy object.
         | 
| 6 | 
            -
                class AdminPolicy <  | 
| 6 | 
            +
                class AdminPolicy < Struct
         | 
| 7 7 | 
             
                  include Checkable
         | 
| 8 8 |  | 
| 9 9 | 
             
                  TYPES = [
         | 
| @@ -11,15 +11,11 @@ module Cocina | |
| 11 11 | 
             
                  ].freeze
         | 
| 12 12 |  | 
| 13 13 | 
             
                  # Subschema for access concerns
         | 
| 14 | 
            -
                  class Access <  | 
| 15 | 
            -
                    def self.from_dynamic(_dyn)
         | 
| 16 | 
            -
                      params = {}
         | 
| 17 | 
            -
                      Access.new(params)
         | 
| 18 | 
            -
                    end
         | 
| 14 | 
            +
                  class Access < Struct
         | 
| 19 15 | 
             
                  end
         | 
| 20 16 |  | 
| 21 17 | 
             
                  # Subschema for administrative concerns
         | 
| 22 | 
            -
                  class Administrative <  | 
| 18 | 
            +
                  class Administrative < Struct
         | 
| 23 19 | 
             
                    # This was copied from the ActiveFedora defaults: Dor::AdminPolicyObject.new.defaultObjectRights.content
         | 
| 24 20 | 
             
                    DEFAULT_OBJECT_RIGHTS = <<~XML
         | 
| 25 21 | 
             
                      <?xml version="1.0" encoding="UTF-8"?>
         | 
| @@ -57,21 +53,12 @@ module Cocina | |
| 57 53 | 
             
                    # Allowing hasAdminPolicy to be omittable for now (until rolled out to consumers),
         | 
| 58 54 | 
             
                    # but I think it's actually required for every Admin Policy
         | 
| 59 55 | 
             
                    attribute :hasAdminPolicy, Types::Coercible::String.optional.default(nil)
         | 
| 60 | 
            -
             | 
| 61 | 
            -
                    def self.from_dynamic(dyn)
         | 
| 62 | 
            -
                      params = {
         | 
| 63 | 
            -
                        default_object_rights: dyn['default_object_rights'],
         | 
| 64 | 
            -
                        registration_workflow: dyn['registration_workflow']
         | 
| 65 | 
            -
                      }
         | 
| 66 | 
            -
                      params[:hasAdminPolicy] = dyn['hasAdminPolicy']
         | 
| 67 | 
            -
                      Administrative.new(params)
         | 
| 68 | 
            -
                    end
         | 
| 69 56 | 
             
                  end
         | 
| 70 57 |  | 
| 71 | 
            -
                  class Identification <  | 
| 58 | 
            +
                  class Identification < Struct
         | 
| 72 59 | 
             
                  end
         | 
| 73 60 |  | 
| 74 | 
            -
                  class Structural <  | 
| 61 | 
            +
                  class Structural < Struct
         | 
| 75 62 | 
             
                  end
         | 
| 76 63 |  | 
| 77 64 | 
             
                  attribute :externalIdentifier, Types::Strict::String
         | 
| @@ -87,7 +74,7 @@ module Cocina | |
| 87 74 | 
             
                  attribute(:structural, Structural.default { Structural.new })
         | 
| 88 75 |  | 
| 89 76 | 
             
                  def self.from_dynamic(dyn)
         | 
| 90 | 
            -
                     | 
| 77 | 
            +
                    AdminPolicy.new(dyn)
         | 
| 91 78 | 
             
                  end
         | 
| 92 79 |  | 
| 93 80 | 
             
                  def self.from_json(json)
         | 
| @@ -3,17 +3,9 @@ | |
| 3 3 | 
             
            module Cocina
         | 
| 4 4 | 
             
              module Models
         | 
| 5 5 | 
             
                # Metadata for a catalog link
         | 
| 6 | 
            -
                class CatalogLink <  | 
| 6 | 
            +
                class CatalogLink < Struct
         | 
| 7 7 | 
             
                  attribute :catalog, Types::Strict::String
         | 
| 8 8 | 
             
                  attribute :catalogRecordId, Types::Strict::String
         | 
| 9 | 
            -
             | 
| 10 | 
            -
                  def self.from_dynamic(dyn)
         | 
| 11 | 
            -
                    params = {
         | 
| 12 | 
            -
                      catalog: dyn['catalog'],
         | 
| 13 | 
            -
                      catalogRecordId: dyn['catalogRecordId']
         | 
| 14 | 
            -
                    }
         | 
| 15 | 
            -
                    CatalogLink.new(params)
         | 
| 16 | 
            -
                  end
         | 
| 17 9 | 
             
                end
         | 
| 18 10 | 
             
              end
         | 
| 19 11 | 
             
            end
         | 
| @@ -3,7 +3,7 @@ | |
| 3 3 | 
             
            module Cocina
         | 
| 4 4 | 
             
              module Models
         | 
| 5 5 | 
             
                # A digital repository collection.  See http://sul-dlss.github.io/cocina-models/maps/Collection.json
         | 
| 6 | 
            -
                class Collection <  | 
| 6 | 
            +
                class Collection < Struct
         | 
| 7 7 | 
             
                  include Checkable
         | 
| 8 8 |  | 
| 9 9 | 
             
                  TYPES = [
         | 
| @@ -15,43 +15,23 @@ module Cocina | |
| 15 15 | 
             
                  ].freeze
         | 
| 16 16 |  | 
| 17 17 | 
             
                  # Subschema for access concerns
         | 
| 18 | 
            -
                  class Access <  | 
| 19 | 
            -
                    def self.from_dynamic(_dyn)
         | 
| 20 | 
            -
                      params = {}
         | 
| 21 | 
            -
                      Access.new(params)
         | 
| 22 | 
            -
                    end
         | 
| 18 | 
            +
                  class Access < Struct
         | 
| 23 19 | 
             
                  end
         | 
| 24 20 |  | 
| 25 21 | 
             
                  # Subschema for administrative concerns
         | 
| 26 | 
            -
                  class Administrative <  | 
| 22 | 
            +
                  class Administrative < Struct
         | 
| 27 23 | 
             
                    attribute :releaseTags, Types::Strict::Array.of(ReleaseTag).default([].freeze)
         | 
| 28 24 | 
             
                    # Allowing hasAdminPolicy to be omittable for now (until rolled out to consumers),
         | 
| 29 25 | 
             
                    # but I think it's actually required for every DRO
         | 
| 30 26 | 
             
                    attribute :hasAdminPolicy, Types::Coercible::String.optional.default(nil)
         | 
| 31 | 
            -
             | 
| 32 | 
            -
                    def self.from_dynamic(dyn)
         | 
| 33 | 
            -
                      params = {}
         | 
| 34 | 
            -
                      params[:releaseTags] = dyn['releaseTags'].map { |rt| ReleaseTag.from_dynamic(rt) } if dyn['releaseTags']
         | 
| 35 | 
            -
                      params[:hasAdminPolicy] = dyn['hasAdminPolicy']
         | 
| 36 | 
            -
                      Administrative.new(params)
         | 
| 37 | 
            -
                    end
         | 
| 38 27 | 
             
                  end
         | 
| 39 28 |  | 
| 40 29 | 
             
                  # Identification sub-schema for the Collection
         | 
| 41 | 
            -
                  class Identification <  | 
| 30 | 
            +
                  class Identification < Struct
         | 
| 42 31 | 
             
                    attribute :catalogLinks, Types::Strict::Array.of(CatalogLink).meta(omittable: true)
         | 
| 43 | 
            -
             | 
| 44 | 
            -
                    def self.from_dynamic(dyn)
         | 
| 45 | 
            -
                      params = {}
         | 
| 46 | 
            -
                      if dyn['catalogLinks']
         | 
| 47 | 
            -
                        params[:catalogLinks] = dyn['catalogLinks']
         | 
| 48 | 
            -
                                                .map { |link| CatalogLink.from_dynamic(link) }
         | 
| 49 | 
            -
                      end
         | 
| 50 | 
            -
                      params
         | 
| 51 | 
            -
                    end
         | 
| 52 32 | 
             
                  end
         | 
| 53 33 |  | 
| 54 | 
            -
                  class Structural <  | 
| 34 | 
            +
                  class Structural < Struct
         | 
| 55 35 | 
             
                  end
         | 
| 56 36 |  | 
| 57 37 | 
             
                  attribute :externalIdentifier, Types::Strict::String
         | 
| @@ -67,7 +47,7 @@ module Cocina | |
| 67 47 | 
             
                  attribute(:structural, Structural.default { Structural.new })
         | 
| 68 48 |  | 
| 69 49 | 
             
                  def self.from_dynamic(dyn)
         | 
| 70 | 
            -
                     | 
| 50 | 
            +
                    Collection.new(dyn)
         | 
| 71 51 | 
             
                  end
         | 
| 72 52 |  | 
| 73 53 | 
             
                  def self.from_json(json)
         | 
| @@ -3,26 +3,14 @@ | |
| 3 3 | 
             
            module Cocina
         | 
| 4 4 | 
             
              module Models
         | 
| 5 5 | 
             
                # Descriptive metadata.  See http://sul-dlss.github.io/cocina-models/maps/Description.json
         | 
| 6 | 
            -
                class Description <  | 
| 6 | 
            +
                class Description < Struct
         | 
| 7 7 | 
             
                  # Title element.  See http://sul-dlss.github.io/cocina-models/maps/Title.json
         | 
| 8 | 
            -
                  class Title <  | 
| 8 | 
            +
                  class Title < Struct
         | 
| 9 9 | 
             
                    attribute :primary, Types::Strict::Bool
         | 
| 10 10 | 
             
                    attribute :titleFull, Types::Strict::String
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                    def self.from_dynamic(dyn)
         | 
| 13 | 
            -
                      Title.new(primary: dyn['primary'],
         | 
| 14 | 
            -
                                titleFull: dyn['titleFull'])
         | 
| 15 | 
            -
                    end
         | 
| 16 11 | 
             
                  end
         | 
| 17 12 |  | 
| 18 13 | 
             
                  attribute :title, Types::Strict::Array.of(Title)
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                  def self.from_dynamic(dyn)
         | 
| 21 | 
            -
                    params = {
         | 
| 22 | 
            -
                      title: dyn.fetch('title').map { |title| Title.from_dynamic(title) }
         | 
| 23 | 
            -
                    }
         | 
| 24 | 
            -
                    Description.new(params)
         | 
| 25 | 
            -
                  end
         | 
| 26 14 | 
             
                end
         | 
| 27 15 | 
             
              end
         | 
| 28 16 | 
             
            end
         | 
    
        data/lib/cocina/models/dro.rb
    CHANGED
    
    | @@ -3,7 +3,7 @@ | |
| 3 3 | 
             
            module Cocina
         | 
| 4 4 | 
             
              module Models
         | 
| 5 5 | 
             
                # A digital repository object.  See http://sul-dlss.github.io/cocina-models/maps/DRO.json
         | 
| 6 | 
            -
                class DRO <  | 
| 6 | 
            +
                class DRO < Struct
         | 
| 7 7 | 
             
                  include Checkable
         | 
| 8 8 |  | 
| 9 9 | 
             
                  TYPES = [
         | 
| @@ -25,57 +25,28 @@ module Cocina | |
| 25 25 | 
             
                  ].freeze
         | 
| 26 26 |  | 
| 27 27 | 
             
                  # Subschema for access concerns
         | 
| 28 | 
            -
                  class Access <  | 
| 28 | 
            +
                  class Access < Struct
         | 
| 29 29 | 
             
                    attribute :embargoReleaseDate, Types::Params::DateTime.meta(omittable: true)
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                    def self.from_dynamic(dyn)
         | 
| 32 | 
            -
                      params = {}
         | 
| 33 | 
            -
                      params[:embargoReleaseDate] = dyn['embargoReleaseDate'] if dyn['embargoReleaseDate']
         | 
| 34 | 
            -
                      Access.new(params)
         | 
| 35 | 
            -
                    end
         | 
| 36 30 | 
             
                  end
         | 
| 37 31 |  | 
| 38 32 | 
             
                  # Subschema for administrative concerns
         | 
| 39 | 
            -
                  class Administrative <  | 
| 33 | 
            +
                  class Administrative < Struct
         | 
| 40 34 | 
             
                    attribute :releaseTags, Types::Strict::Array.of(ReleaseTag).meta(omittable: true).default([].freeze)
         | 
| 41 35 | 
             
                    # Allowing hasAdminPolicy to be omittable for now (until rolled out to consumers),
         | 
| 42 36 | 
             
                    # but I think it's actually required for every DRO
         | 
| 43 37 | 
             
                    attribute :hasAdminPolicy, Types::Coercible::String.optional.default(nil)
         | 
| 44 | 
            -
             | 
| 45 | 
            -
                    def self.from_dynamic(dyn)
         | 
| 46 | 
            -
                      params = {}
         | 
| 47 | 
            -
                      params[:releaseTags] = dyn['releaseTags'].map { |rt| ReleaseTag.from_dynamic(rt) } if dyn['releaseTags']
         | 
| 48 | 
            -
                      params[:hasAdminPolicy] = dyn['hasAdminPolicy']
         | 
| 49 | 
            -
                      Administrative.new(params)
         | 
| 50 | 
            -
                    end
         | 
| 51 38 | 
             
                  end
         | 
| 52 39 |  | 
| 53 40 | 
             
                  # Identification sub-schema for the DRO
         | 
| 54 | 
            -
                  class Identification <  | 
| 41 | 
            +
                  class Identification < Struct
         | 
| 55 42 | 
             
                    attribute :sourceId, Types::Strict::String.meta(omittable: true)
         | 
| 56 43 | 
             
                    attribute :catalogLinks, Types::Strict::Array.of(CatalogLink).meta(omittable: true)
         | 
| 57 | 
            -
                    def self.from_dynamic(dyn)
         | 
| 58 | 
            -
                      params = {}
         | 
| 59 | 
            -
                      params[:sourceId] = dyn['sourceId'] if dyn['sourceId']
         | 
| 60 | 
            -
                      if dyn['catalogLinks']
         | 
| 61 | 
            -
                        params[:catalogLinks] = dyn['catalogLinks']
         | 
| 62 | 
            -
                                                .map { |link| CatalogLink.from_dynamic(link) }
         | 
| 63 | 
            -
                      end
         | 
| 64 | 
            -
                      params
         | 
| 65 | 
            -
                    end
         | 
| 66 44 | 
             
                  end
         | 
| 67 45 |  | 
| 68 46 | 
             
                  # Structural sub-schema for the DRO
         | 
| 69 | 
            -
                  class Structural <  | 
| 47 | 
            +
                  class Structural < Struct
         | 
| 70 48 | 
             
                    attribute :contains, Types::Strict::Array.of(FileSet).meta(omittable: true)
         | 
| 71 49 | 
             
                    attribute :isMemberOf, Types::Strict::String.meta(omittable: true)
         | 
| 72 | 
            -
             | 
| 73 | 
            -
                    def self.from_dynamic(dyn)
         | 
| 74 | 
            -
                      params = {}
         | 
| 75 | 
            -
                      params[:isMemberOf] = dyn['isMemberOf'] if dyn['isMemberOf']
         | 
| 76 | 
            -
                      params[:contains] = dyn['contains'].map { |fs| FileSet.from_dynamic(fs) } if dyn['contains']
         | 
| 77 | 
            -
                      Structural.new(params)
         | 
| 78 | 
            -
                    end
         | 
| 79 50 | 
             
                  end
         | 
| 80 51 |  | 
| 81 52 | 
             
                  attribute :externalIdentifier, Types::Strict::String
         | 
| @@ -91,7 +62,7 @@ module Cocina | |
| 91 62 | 
             
                  attribute(:structural, Structural.default { Structural.new })
         | 
| 92 63 |  | 
| 93 64 | 
             
                  def self.from_dynamic(dyn)
         | 
| 94 | 
            -
                     | 
| 65 | 
            +
                    DRO.new(dyn)
         | 
| 95 66 | 
             
                  end
         | 
| 96 67 |  | 
| 97 68 | 
             
                  def self.from_json(json)
         | 
    
        data/lib/cocina/models/file.rb
    CHANGED
    
    | @@ -3,7 +3,7 @@ | |
| 3 3 | 
             
            module Cocina
         | 
| 4 4 | 
             
              module Models
         | 
| 5 5 | 
             
                # Metadata for a file.  See http://sul-dlss.github.io/cocina-models/maps/File.json
         | 
| 6 | 
            -
                class File <  | 
| 6 | 
            +
                class File < Struct
         | 
| 7 7 | 
             
                  include Checkable
         | 
| 8 8 |  | 
| 9 9 | 
             
                  TYPES = [
         | 
| @@ -11,72 +11,33 @@ module Cocina | |
| 11 11 | 
             
                  ].freeze
         | 
| 12 12 |  | 
| 13 13 | 
             
                  # Represents access controls on the file
         | 
| 14 | 
            -
                  class Access <  | 
| 14 | 
            +
                  class Access < Struct
         | 
| 15 15 | 
             
                    attribute :access, Types::String.default('dark')
         | 
| 16 16 | 
             
                                                    .enum('world', 'stanford', 'location-based', 'citation-only', 'dark')
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                    def self.from_dynamic(dyn)
         | 
| 19 | 
            -
                      return unless dyn
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                      params = {}
         | 
| 22 | 
            -
                      params[:access] = dyn['access'] if dyn['access']
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                      Access.new(params)
         | 
| 25 | 
            -
                    end
         | 
| 26 17 | 
             
                  end
         | 
| 27 18 |  | 
| 28 19 | 
             
                  # Represents the administration of the file
         | 
| 29 | 
            -
                  class Administrative <  | 
| 20 | 
            +
                  class Administrative < Struct
         | 
| 30 21 | 
             
                    attribute :sdrPreserve, Types::Params::Bool.optional.default(false)
         | 
| 31 22 | 
             
                    attribute :shelve, Types::Params::Bool.optional.default(false)
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                    def self.from_dynamic(dyn)
         | 
| 34 | 
            -
                      return unless dyn
         | 
| 35 | 
            -
             | 
| 36 | 
            -
                      params = {
         | 
| 37 | 
            -
                        sdrPreserve: dyn['sdrPreserve'],
         | 
| 38 | 
            -
                        shelve: dyn['shelve']
         | 
| 39 | 
            -
                      }
         | 
| 40 | 
            -
                      Administrative.new(params)
         | 
| 41 | 
            -
                    end
         | 
| 42 23 | 
             
                  end
         | 
| 43 24 |  | 
| 44 | 
            -
                  class Identification <  | 
| 25 | 
            +
                  class Identification < Struct
         | 
| 45 26 | 
             
                  end
         | 
| 46 27 |  | 
| 47 | 
            -
                  class Structural <  | 
| 28 | 
            +
                  class Structural < Struct
         | 
| 48 29 | 
             
                  end
         | 
| 49 30 |  | 
| 50 31 | 
             
                  # Represents a digest value for a file
         | 
| 51 | 
            -
                  class Fixity <  | 
| 32 | 
            +
                  class Fixity < Struct
         | 
| 52 33 | 
             
                    attribute :type, Types::String.enum('md5', 'sha1')
         | 
| 53 34 | 
             
                    attribute :digest, Types::Strict::String
         | 
| 54 | 
            -
             | 
| 55 | 
            -
                    def self.from_dynamic(dyn)
         | 
| 56 | 
            -
                      params = {
         | 
| 57 | 
            -
                        type: dyn['type'],
         | 
| 58 | 
            -
                        digest: dyn['digest']
         | 
| 59 | 
            -
                      }
         | 
| 60 | 
            -
             | 
| 61 | 
            -
                      Fixity.new(params)
         | 
| 62 | 
            -
                    end
         | 
| 63 35 | 
             
                  end
         | 
| 64 36 |  | 
| 65 37 | 
             
                  # Represents some technical aspect of the file
         | 
| 66 | 
            -
                  class Presentation <  | 
| 38 | 
            +
                  class Presentation < Struct
         | 
| 67 39 | 
             
                    attribute :height, Types::Coercible::Integer.optional.default(nil)
         | 
| 68 40 | 
             
                    attribute :width, Types::Coercible::Integer.optional.default(nil)
         | 
| 69 | 
            -
             | 
| 70 | 
            -
                    def self.from_dynamic(dyn)
         | 
| 71 | 
            -
                      return unless dyn
         | 
| 72 | 
            -
             | 
| 73 | 
            -
                      params = {
         | 
| 74 | 
            -
                        height: dyn['height'],
         | 
| 75 | 
            -
                        width: dyn['width']
         | 
| 76 | 
            -
                      }
         | 
| 77 | 
            -
             | 
| 78 | 
            -
                      Presentation.new(params)
         | 
| 79 | 
            -
                    end
         | 
| 80 41 | 
             
                  end
         | 
| 81 42 |  | 
| 82 43 | 
             
                  attribute(:access, Access.optional.default { Access.new })
         | 
| @@ -94,19 +55,7 @@ module Cocina | |
| 94 55 | 
             
                  attribute(:structural, Structural.default { Structural.new })
         | 
| 95 56 |  | 
| 96 57 | 
             
                  def self.from_dynamic(dyn)
         | 
| 97 | 
            -
                     | 
| 98 | 
            -
                      externalIdentifier: dyn['externalIdentifier'],
         | 
| 99 | 
            -
                      type: dyn['type'],
         | 
| 100 | 
            -
                      label: dyn['label'],
         | 
| 101 | 
            -
                      version: dyn['version'],
         | 
| 102 | 
            -
                      size: dyn['size'],
         | 
| 103 | 
            -
                      use: dyn['use']
         | 
| 104 | 
            -
                    }
         | 
| 105 | 
            -
                    params[:administrative] = Administrative.from_dynamic(dyn['administrative'])
         | 
| 106 | 
            -
                    params[:presentation] = Presentation.from_dynamic(dyn['presentation'])
         | 
| 107 | 
            -
                    params[:access] = Access.from_dynamic(dyn['access'])
         | 
| 108 | 
            -
                    params[:hasMessageDigests] = Array(dyn['hasMessageDigests']).map { |p| Fixity.from_dynamic(p) }
         | 
| 109 | 
            -
                    File.new(params)
         | 
| 58 | 
            +
                    File.new(dyn)
         | 
| 110 59 | 
             
                  end
         | 
| 111 60 |  | 
| 112 61 | 
             
                  def self.from_json(json)
         | 
| @@ -3,25 +3,19 @@ | |
| 3 3 | 
             
            module Cocina
         | 
| 4 4 | 
             
              module Models
         | 
| 5 5 | 
             
                # Metadata for a File Set.  See http://sul-dlss.github.io/cocina-models/maps/Fileset.json
         | 
| 6 | 
            -
                class FileSet <  | 
| 6 | 
            +
                class FileSet < Struct
         | 
| 7 7 | 
             
                  include Checkable
         | 
| 8 8 |  | 
| 9 9 | 
             
                  TYPES = [
         | 
| 10 10 | 
             
                    Vocab.fileset
         | 
| 11 11 | 
             
                  ].freeze
         | 
| 12 12 |  | 
| 13 | 
            -
                  class Identification <  | 
| 13 | 
            +
                  class Identification < Struct
         | 
| 14 14 | 
             
                  end
         | 
| 15 15 |  | 
| 16 16 | 
             
                  # Structural sub-schema for the FileSet
         | 
| 17 | 
            -
                  class Structural <  | 
| 17 | 
            +
                  class Structural < Struct
         | 
| 18 18 | 
             
                    attribute :contains, Types::Strict::Array.of(Cocina::Models::File).meta(omittable: true)
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                    def self.from_dynamic(dyn)
         | 
| 21 | 
            -
                      params = {}
         | 
| 22 | 
            -
                      params[:contains] = dyn['contains'].map { |f| Cocina::Models::File.from_dynamic(f) } if dyn['contains']
         | 
| 23 | 
            -
                      Structural.new(params)
         | 
| 24 | 
            -
                    end
         | 
| 25 19 | 
             
                  end
         | 
| 26 20 |  | 
| 27 21 | 
             
                  attribute :externalIdentifier, Types::Strict::String
         | 
| @@ -32,21 +26,7 @@ module Cocina | |
| 32 26 | 
             
                  attribute(:structural, Structural.default { Structural.new })
         | 
| 33 27 |  | 
| 34 28 | 
             
                  def self.from_dynamic(dyn)
         | 
| 35 | 
            -
                     | 
| 36 | 
            -
                      externalIdentifier: dyn['externalIdentifier'],
         | 
| 37 | 
            -
                      type: dyn['type'],
         | 
| 38 | 
            -
                      label: dyn['label'],
         | 
| 39 | 
            -
                      version: dyn['version'],
         | 
| 40 | 
            -
                      size: dyn['size'],
         | 
| 41 | 
            -
                      use: dyn['use']
         | 
| 42 | 
            -
                    }
         | 
| 43 | 
            -
                    params[:presentation] = Presentation.from_dynamic(dyn['presentation']) if dyn['presentation']
         | 
| 44 | 
            -
                    if dyn['hasMessageDigests']
         | 
| 45 | 
            -
                      params[:hasMessageDigests] = dyn['hasMessageDigests'].map { |p| Fixity.from_dynamic(p) }
         | 
| 46 | 
            -
                    end
         | 
| 47 | 
            -
                    params[:structural] = Structural.from_dynamic(dyn['structural']) if dyn['structural']
         | 
| 48 | 
            -
             | 
| 49 | 
            -
                    FileSet.new(params)
         | 
| 29 | 
            +
                    FileSet.new(dyn)
         | 
| 50 30 | 
             
                  end
         | 
| 51 31 |  | 
| 52 32 | 
             
                  def self.from_json(json)
         | 
| @@ -3,7 +3,7 @@ | |
| 3 3 | 
             
            module Cocina
         | 
| 4 4 | 
             
              module Models
         | 
| 5 5 | 
             
                # Subschema for release tags
         | 
| 6 | 
            -
                class ReleaseTag <  | 
| 6 | 
            +
                class ReleaseTag < Struct
         | 
| 7 7 | 
             
                  attribute :to, Types::Strict::String.enum('Searchworks', 'Earthworks')
         | 
| 8 8 | 
             
                  attribute :what, Types::Strict::String.enum('self', 'collection')
         | 
| 9 9 | 
             
                  # we use 'when' other places, but that's reserved word, so 'date' it is!
         | 
| @@ -12,11 +12,7 @@ module Cocina | |
| 12 12 | 
             
                  attribute :release, Types::Params::Bool
         | 
| 13 13 |  | 
| 14 14 | 
             
                  def self.from_dynamic(dyn)
         | 
| 15 | 
            -
                    ReleaseTag.new( | 
| 16 | 
            -
                                   what: dyn['what'],
         | 
| 17 | 
            -
                                   date: dyn['date'],
         | 
| 18 | 
            -
                                   who: dyn['who'],
         | 
| 19 | 
            -
                                   release: dyn['release'])
         | 
| 15 | 
            +
                    ReleaseTag.new(dyn)
         | 
| 20 16 | 
             
                  end
         | 
| 21 17 | 
             
                end
         | 
| 22 18 | 
             
              end
         | 
| @@ -4,7 +4,7 @@ module Cocina | |
| 4 4 | 
             
              module Models
         | 
| 5 5 | 
             
                # An request to create an AdminPolicy object.
         | 
| 6 6 | 
             
                # This is the same as AdminPolicy, except it doesn't have externalIdentifier.
         | 
| 7 | 
            -
                class RequestAdminPolicy <  | 
| 7 | 
            +
                class RequestAdminPolicy < Struct
         | 
| 8 8 | 
             
                  attribute :type, Types::String.enum(*AdminPolicy::TYPES)
         | 
| 9 9 | 
             
                  attribute :label, Types::Strict::String
         | 
| 10 10 | 
             
                  attribute :version, Types::Coercible::Integer
         | 
| @@ -17,7 +17,7 @@ module Cocina | |
| 17 17 | 
             
                  attribute(:structural, AdminPolicy::Structural.default { AdminPolicy::Structural.new })
         | 
| 18 18 |  | 
| 19 19 | 
             
                  def self.from_dynamic(dyn)
         | 
| 20 | 
            -
                     | 
| 20 | 
            +
                    RequestAdminPolicy.new(dyn)
         | 
| 21 21 | 
             
                  end
         | 
| 22 22 |  | 
| 23 23 | 
             
                  def self.from_json(json)
         | 
| @@ -5,7 +5,7 @@ module Cocina | |
| 5 5 | 
             
                # A request to create a digital repository collection.
         | 
| 6 6 | 
             
                # This is the same as Collection, except it doesn't have externalIdentifier.
         | 
| 7 7 | 
             
                # See http://sul-dlss.github.io/cocina-models/maps/Collection.json
         | 
| 8 | 
            -
                class RequestCollection <  | 
| 8 | 
            +
                class RequestCollection < Struct
         | 
| 9 9 | 
             
                  attribute :type, Types::String.enum(*Collection::TYPES)
         | 
| 10 10 | 
             
                  attribute :label, Types::Strict::String
         | 
| 11 11 | 
             
                  attribute :version, Types::Coercible::Integer
         | 
| @@ -18,7 +18,7 @@ module Cocina | |
| 18 18 | 
             
                  attribute(:structural, Collection::Structural.default { Collection::Structural.new })
         | 
| 19 19 |  | 
| 20 20 | 
             
                  def self.from_dynamic(dyn)
         | 
| 21 | 
            -
                     | 
| 21 | 
            +
                    RequestCollection.new(dyn)
         | 
| 22 22 | 
             
                  end
         | 
| 23 23 |  | 
| 24 24 | 
             
                  def self.from_json(json)
         | 
| @@ -5,7 +5,7 @@ module Cocina | |
| 5 5 | 
             
                # A Request to create a digital repository object. (to create) object.
         | 
| 6 6 | 
             
                # This is same as a DRO, but without externalIdentifier (as that wouldn't have been created yet)
         | 
| 7 7 | 
             
                # See http://sul-dlss.github.io/cocina-models/maps/DRO.json
         | 
| 8 | 
            -
                class RequestDRO <  | 
| 8 | 
            +
                class RequestDRO < Struct
         | 
| 9 9 | 
             
                  attribute :type, Types::String.enum(*DRO::TYPES)
         | 
| 10 10 | 
             
                  attribute :label, Types::Strict::String
         | 
| 11 11 | 
             
                  attribute :version, Types::Coercible::Integer
         | 
| @@ -18,7 +18,7 @@ module Cocina | |
| 18 18 | 
             
                  attribute(:structural, DRO::Structural.default { DRO::Structural.new })
         | 
| 19 19 |  | 
| 20 20 | 
             
                  def self.from_dynamic(dyn)
         | 
| 21 | 
            -
                     | 
| 21 | 
            +
                    RequestDRO.new(dyn)
         | 
| 22 22 | 
             
                  end
         | 
| 23 23 |  | 
| 24 24 | 
             
                  def self.from_json(json)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: cocina-models
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.20.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Justin Coyne
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2020-02- | 
| 11 | 
            +
            date: 2020-02-13 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: dry-struct
         | 
| @@ -177,14 +177,11 @@ files: | |
| 177 177 | 
             
            - docs/schema.md
         | 
| 178 178 | 
             
            - lib/cocina/models.rb
         | 
| 179 179 | 
             
            - lib/cocina/models/admin_policy.rb
         | 
| 180 | 
            -
            - lib/cocina/models/admin_policy_builder.rb
         | 
| 181 180 | 
             
            - lib/cocina/models/catalog_link.rb
         | 
| 182 181 | 
             
            - lib/cocina/models/checkable.rb
         | 
| 183 182 | 
             
            - lib/cocina/models/collection.rb
         | 
| 184 | 
            -
            - lib/cocina/models/collection_builder.rb
         | 
| 185 183 | 
             
            - lib/cocina/models/description.rb
         | 
| 186 184 | 
             
            - lib/cocina/models/dro.rb
         | 
| 187 | 
            -
            - lib/cocina/models/dro_builder.rb
         | 
| 188 185 | 
             
            - lib/cocina/models/file.rb
         | 
| 189 186 | 
             
            - lib/cocina/models/file_set.rb
         | 
| 190 187 | 
             
            - lib/cocina/models/release_tag.rb
         | 
| @@ -1,30 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module Cocina
         | 
| 4 | 
            -
              module Models
         | 
| 5 | 
            -
                # This creates an AdminPolicy or a RequestAdminPolicy from dynamic attributes
         | 
| 6 | 
            -
                class AdminPolicyBuilder
         | 
| 7 | 
            -
                  # @return [AdminPolicy,RequestAdminPolicy]
         | 
| 8 | 
            -
                  def self.build(klass, dyn)
         | 
| 9 | 
            -
                    params = {
         | 
| 10 | 
            -
                      type: dyn['type'],
         | 
| 11 | 
            -
                      label: dyn['label'],
         | 
| 12 | 
            -
                      version: dyn['version']
         | 
| 13 | 
            -
                    }
         | 
| 14 | 
            -
                    params[:externalIdentifier] = dyn['externalIdentifier'] if needs_id?(klass)
         | 
| 15 | 
            -
             | 
| 16 | 
            -
                    # params[:access] = Access.from_dynamic(dyn['access']) if dyn['access']
         | 
| 17 | 
            -
                    if dyn['administrative']
         | 
| 18 | 
            -
                      params[:administrative] = AdminPolicy::Administrative
         | 
| 19 | 
            -
                                                .from_dynamic(dyn['administrative'])
         | 
| 20 | 
            -
                    end
         | 
| 21 | 
            -
                    params[:description] = Description.from_dynamic(dyn.fetch('description'))
         | 
| 22 | 
            -
                    klass.new(params)
         | 
| 23 | 
            -
                  end
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                  def self.needs_id?(klass)
         | 
| 26 | 
            -
                    klass.attribute_names.include?(:externalIdentifier)
         | 
| 27 | 
            -
                  end
         | 
| 28 | 
            -
                end
         | 
| 29 | 
            -
              end
         | 
| 30 | 
            -
            end
         | 
| @@ -1,35 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module Cocina
         | 
| 4 | 
            -
              module Models
         | 
| 5 | 
            -
                # This creates a Collection or a RequestCollection from dynamic attributes
         | 
| 6 | 
            -
                class CollectionBuilder
         | 
| 7 | 
            -
                  # @return [Collection,RequestCollection]
         | 
| 8 | 
            -
                  # rubocop:disable Metrics/MethodLength
         | 
| 9 | 
            -
                  def self.build(klass, dyn)
         | 
| 10 | 
            -
                    params = {
         | 
| 11 | 
            -
                      type: dyn['type'],
         | 
| 12 | 
            -
                      label: dyn['label'],
         | 
| 13 | 
            -
                      version: dyn['version'],
         | 
| 14 | 
            -
                      description: Description.from_dynamic(dyn.fetch('description'))
         | 
| 15 | 
            -
                    }
         | 
| 16 | 
            -
                    params[:externalIdentifier] = dyn['externalIdentifier'] if needs_id?(klass)
         | 
| 17 | 
            -
                    # params[:access] = Access.from_dynamic(dyn['access']) if dyn['access']
         | 
| 18 | 
            -
                    if dyn['administrative']
         | 
| 19 | 
            -
                      params[:administrative] = Collection::Administrative
         | 
| 20 | 
            -
                                                .from_dynamic(dyn['administrative'])
         | 
| 21 | 
            -
                    end
         | 
| 22 | 
            -
                    if dyn['identification']
         | 
| 23 | 
            -
                      params[:identification] = Collection::Identification
         | 
| 24 | 
            -
                                                .from_dynamic(dyn['identification'])
         | 
| 25 | 
            -
                    end
         | 
| 26 | 
            -
                    klass.new(params)
         | 
| 27 | 
            -
                  end
         | 
| 28 | 
            -
                  # rubocop:enable Metrics/MethodLength
         | 
| 29 | 
            -
             | 
| 30 | 
            -
                  def self.needs_id?(klass)
         | 
| 31 | 
            -
                    klass.attribute_names.include?(:externalIdentifier)
         | 
| 32 | 
            -
                  end
         | 
| 33 | 
            -
                end
         | 
| 34 | 
            -
              end
         | 
| 35 | 
            -
            end
         | 
| @@ -1,31 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module Cocina
         | 
| 4 | 
            -
              module Models
         | 
| 5 | 
            -
                # This creates a DRO or a RequestDRO from dynamic attributes
         | 
| 6 | 
            -
                class DROBuilder
         | 
| 7 | 
            -
                  # @return [DRO,RequestDRO]
         | 
| 8 | 
            -
                  # rubocop:disable Metrics/AbcSize
         | 
| 9 | 
            -
                  def self.build(klass, dyn)
         | 
| 10 | 
            -
                    params = {
         | 
| 11 | 
            -
                      type: dyn['type'],
         | 
| 12 | 
            -
                      label: dyn['label'],
         | 
| 13 | 
            -
                      version: dyn['version'],
         | 
| 14 | 
            -
                      description: Description.from_dynamic(dyn.fetch('description'))
         | 
| 15 | 
            -
                    }
         | 
| 16 | 
            -
                    params[:externalIdentifier] = dyn['externalIdentifier'] if needs_id?(klass)
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                    params[:access] = DRO::Access.from_dynamic(dyn['access']) if dyn['access']
         | 
| 19 | 
            -
                    params[:administrative] = DRO::Administrative.from_dynamic(dyn['administrative']) if dyn['administrative']
         | 
| 20 | 
            -
                    params[:identification] = DRO::Identification.from_dynamic(dyn['identification']) if dyn['identification']
         | 
| 21 | 
            -
                    params[:structural] = DRO::Structural.from_dynamic(dyn['structural']) if dyn['structural']
         | 
| 22 | 
            -
                    klass.new(params)
         | 
| 23 | 
            -
                  end
         | 
| 24 | 
            -
                  # rubocop:enable Metrics/AbcSize
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                  def self.needs_id?(klass)
         | 
| 27 | 
            -
                    klass.attribute_names.include?(:externalIdentifier)
         | 
| 28 | 
            -
                  end
         | 
| 29 | 
            -
                end
         | 
| 30 | 
            -
              end
         | 
| 31 | 
            -
            end
         |