cocina-models 0.18.0 → 0.19.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb44299e9e86c9fdde5589710db813e3691add7bbf59b14d34ab6edf89cffa9b
4
- data.tar.gz: a63852fd6c5a8369ff49236b4fea55504dfaa3e0944fcc74e6da03605031e504
3
+ metadata.gz: eaac4eacd465708a36f6f62f975cf1af58eb17015ada6ce45785564547ab4e0e
4
+ data.tar.gz: 521e3b949290b6f61fd8a2b83ed984ae2fc4a5e5598ea3eab3a42765cf311218
5
5
  SHA512:
6
- metadata.gz: be279159d4b042bc5265db234d6f938bcecfafd5240c969a5f5f77af6acf7a00aadfad6076110f3674596f7354b435c526de2559067fbd53539907e209c28369
7
- data.tar.gz: 1bab7879c6051415a51226b5abd983f38fdc883dd93d5053c39240a51943e1ca4baae19034929861edc4579fa7fdca0b4b61bd4a08aab5539ebd7bb45ee520b6
6
+ metadata.gz: 51b3220584a9ac5ddfb75522b1def45b1f6f661f4fdb6259582f162b91db7d6b558f4dc9e6a752d9d85b49d4e6b622827397ff5612a97de4e0bee6cc6408c2e6
7
+ data.tar.gz: 2c0b9891af645153ddeb6c4ad4dec22c1af8fb413c6a47f546baf641c4b7a2e404fcdc31fd0fcec0ed219d2e23bde03f54366ec35248f8c1af81c6280cc67baa
@@ -87,17 +87,7 @@ module Cocina
87
87
  attribute(:structural, Structural.default { Structural.new })
88
88
 
89
89
  def self.from_dynamic(dyn)
90
- params = {
91
- externalIdentifier: dyn['externalIdentifier'],
92
- type: dyn['type'],
93
- label: dyn['label'],
94
- version: dyn['version']
95
- }
96
-
97
- # params[:access] = Access.from_dynamic(dyn['access']) if dyn['access']
98
- params[:administrative] = Administrative.from_dynamic(dyn['administrative']) if dyn['administrative']
99
- params[:description] = Description.from_dynamic(dyn.fetch('description'))
100
- AdminPolicy.new(params)
90
+ AdminPolicyBuilder.build(self, dyn)
101
91
  end
102
92
 
103
93
  def self.from_json(json)
@@ -0,0 +1,30 @@
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
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cocina
4
+ module Models
5
+ # An request to create an AdminPolicy object.
6
+ # This is the same as AdminPolicy, except it doesn't have externalIdentifier.
7
+ class RequestAdminPolicy < Dry::Struct
8
+ attribute :type, Types::String.enum(*AdminPolicy::TYPES)
9
+ attribute :label, Types::Strict::String
10
+ attribute :version, Types::Coercible::Integer
11
+ attribute(:access, AdminPolicy::Access.default { AdminPolicy::Access.new })
12
+ attribute(:administrative, AdminPolicy::Administrative.default { AdminPolicy::Administrative.new })
13
+ # Allowing description to be omittable for now (until rolled out to consumers),
14
+ # but I think it's actually required for every DRO
15
+ attribute :description, Description.optional.default(nil)
16
+ attribute(:identification, AdminPolicy::Identification.default { AdminPolicy::Identification.new })
17
+ attribute(:structural, AdminPolicy::Structural.default { AdminPolicy::Structural.new })
18
+
19
+ def self.from_dynamic(dyn)
20
+ AdminPolicyBuilder.build(self, dyn)
21
+ end
22
+
23
+ def self.from_json(json)
24
+ from_dynamic(JSON.parse(json))
25
+ end
26
+ end
27
+ end
28
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Cocina
4
4
  module Models
5
- VERSION = '0.18.0'
5
+ VERSION = '0.19.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocina-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
@@ -177,6 +177,7 @@ 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
180
181
  - lib/cocina/models/catalog_link.rb
181
182
  - lib/cocina/models/checkable.rb
182
183
  - lib/cocina/models/collection.rb
@@ -187,6 +188,7 @@ files:
187
188
  - lib/cocina/models/file.rb
188
189
  - lib/cocina/models/file_set.rb
189
190
  - lib/cocina/models/release_tag.rb
191
+ - lib/cocina/models/request_admin_policy.rb
190
192
  - lib/cocina/models/request_collection.rb
191
193
  - lib/cocina/models/request_dro.rb
192
194
  - lib/cocina/models/types.rb