Sha256: c10435e012677841d73597cb5b4c8caeab25f1646ce78e9e18e9da1713f94550

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

require 'json'

module Cocina
  module Models
    # An admin policy object.
    class AdminPolicy < Dry::Struct
      TYPES = [
        Vocab.admin_policy
      ].freeze

      # Subschema for access concerns
      class Access < Dry::Struct
        def self.from_dynamic(_dyn)
          params = {}
          Access.new(params)
        end
      end

      # Subschema for administrative concerns
      class Administrative < Dry::Struct
        def self.from_dynamic(_dyn)
          params = {}
          Administrative.new(params)
        end
      end

      class Identification < Dry::Struct
      end

      class Structural < Dry::Struct
      end

      attribute :externalIdentifier, Types::Strict::String
      attribute :type, Types::String.enum(*TYPES)
      attribute :label, Types::Strict::String
      attribute :version, Types::Coercible::Integer
      attribute(:access, Access.default { Access.new })
      attribute(:administrative, Administrative.default { Administrative.new })
      attribute(:identification, Identification.default { Identification.new })
      attribute(:structural, Structural.default { Structural.new })

      def self.from_dynamic(dyn)
        params = {
          externalIdentifier: dyn['externalIdentifier'],
          type: dyn['type'],
          label: dyn['label'],
          version: dyn['version']
        }

        # params[:access] = Access.from_dynamic(dyn['access']) if dyn['access']
        # params[:administrative] = Administrative.from_dynamic(dyn['administrative']) if dyn['administrative']

        AdminPolicy.new(params)
      end

      def self.from_json(json)
        from_dynamic(JSON.parse(json))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cocina-models-0.8.0 lib/cocina/models/admin_policy.rb