valkyrie-sequel 2.2.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02c82c0908c1a17e60365ffe3b82936ffed1c168ccc40183d78fc60000b4e7da
4
- data.tar.gz: 434ff68cfb53eab85acc6cbe6eefe691d27eea0e01e0249475b97675c0da5f68
3
+ metadata.gz: 496f6b385edcc29f60fee0e1aecd6c932e2f320b409485c42bac7b7091099c0d
4
+ data.tar.gz: 6f1140aa0b3625ce987748a94a478f0f4df8e1e3ef4be34ed0ef88bd36cc28dc
5
5
  SHA512:
6
- metadata.gz: 1bf48b6add481dcd51d4f02f3a0454d8144f6d39106a264510e5f02c0764769344cdb343a8f05038b94614d79b3b16cc0430a25a683f5b0f047cca7d8c072768
7
- data.tar.gz: 00a6c97708c6f3653497f158d1a0aded088a73908d9559c4f276ae02f2768826a2ddb7306fa41ed5a1d146062f196f63995b5a7f6f0f4bbcc39c4e569e695446
6
+ metadata.gz: 3c36213fca14199daea5605a8921757ac03e2255d65b6fd0a14c0cfab35a7ef6e84a20f644e5c09484e119ddc6266c29bd69d97c2abca6f90d90c5b16b483b08
7
+ data.tar.gz: 1a6eaf749712845d9af4a412fc9c07a7530b93d699efdbb9a10c4f6466bbf2451518de0475f959fcbdb69f270ef590e7ca19592db16533881d4d38140c901e80
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # changelog
2
+
3
+ ## 3.0.0
4
+
5
+ https://github.com/samvera-labs/valkyrie-sequel/compare/v2.2.1...main
6
+
7
+ - support Valkyrie 3.x (@tpendragon, @no-reply)
8
+ - support `resource_class_resolver` in `resource_klass` (@marrus-sh, [#48](https://github.com/samvera-labs/valkyrie-sequel/pull/48))
@@ -8,9 +8,9 @@ module Valkyrie::Sequel
8
8
  @adapter = adapter
9
9
  end
10
10
 
11
- def save(resource:)
11
+ def save(resource:, external_resource: false)
12
12
  object_attributes = resource_factory.from_resource(resource: resource)
13
- output = create_or_update(resource: resource, attributes: object_attributes)
13
+ output = create_or_update(resource: resource, attributes: object_attributes, external_resource: external_resource)
14
14
  resource_factory.to_resource(object: output)
15
15
  end
16
16
 
@@ -41,6 +41,7 @@ module Valkyrie::Sequel
41
41
  grouped_resources = resources.group_by(&:optimistic_locking_enabled?)
42
42
  locked_resources = grouped_resources[true] || []
43
43
  unlocked_resources = grouped_resources[false] || []
44
+
44
45
  CompositePersister.new(
45
46
  [
46
47
  SaveAllPersister.new(resources: locked_resources, relation: locking_relation, resource_factory: resource_factory),
@@ -98,6 +99,7 @@ module Valkyrie::Sequel
98
99
  output
99
100
  end
100
101
  end
102
+
101
103
  class CompositePersister
102
104
  attr_reader :persisters
103
105
  def initialize(persisters)
@@ -121,16 +123,23 @@ module Valkyrie::Sequel
121
123
 
122
124
  private
123
125
 
124
- def create_or_update(resource:, attributes:)
126
+ def create_or_update(resource:, attributes:, external_resource:)
125
127
  attributes[:updated_at] = Time.now.utc
126
128
  attributes[:created_at] ||= Time.now.utc
127
- return create(resource: resource, attributes: attributes) unless resource.persisted? && !exists?(id: attributes[:id])
128
- update(resource: resource, attributes: attributes)
129
+ if exists?(id: attributes[:id])
130
+ update(resource: resource, attributes: attributes)
131
+ else
132
+ if !external_resource && resource.persisted?
133
+ # This resource has been deleted in the meantime, error.
134
+ raise Valkyrie::Persistence::ObjectNotFoundError, "The object #{resource.id} is previously persisted but not found at save time." unless exists?(id: attributes[:id])
135
+ end
136
+ create(resource: resource, attributes: attributes)
137
+ end
129
138
  end
130
139
 
131
140
  def create(resource:, attributes:)
132
141
  attributes[:lock_version] = 0 if resource.optimistic_locking_enabled? && resources.columns.include?(:lock_version)
133
- Array(resources.returning.insert(attributes)).first
142
+ Array(resources.returning.insert(attributes)).first # rubocop:disable Rails/SkipsModelValidations
134
143
  end
135
144
 
136
145
  def update(resource:, attributes:)
@@ -146,7 +155,7 @@ module Valkyrie::Sequel
146
155
  end
147
156
 
148
157
  def exists?(id:)
149
- resources.select(1).first(id: id).nil?
158
+ !resources.select(1).first(id: id).nil?
150
159
  end
151
160
  end
152
161
  end
@@ -38,7 +38,7 @@ module Valkyrie::Sequel
38
38
  # Retrieve the Class used to construct the Valkyrie Resource
39
39
  # @return [Class]
40
40
  def resource_klass
41
- internal_resource.constantize
41
+ Valkyrie.config.resource_class_resolver.call(internal_resource)
42
42
  end
43
43
 
44
44
  # Access the String for the Valkyrie Resource type within the attributes
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Valkyrie
3
3
  module Sequel
4
- VERSION = "2.2.1"
4
+ VERSION = "3.0.0"
5
5
  end
6
6
  end
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_dependency "sequel", "~> 5.0"
24
24
  spec.add_dependency "sequel_pg", "~> 1.0"
25
- spec.add_dependency "valkyrie", ">= 2.1", "< 2.3"
25
+ spec.add_dependency "valkyrie", "~> 3.0"
26
26
  spec.add_dependency "oj", "~> 3.0"
27
27
  spec.add_development_dependency "bundler", "~> 2.0"
28
28
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valkyrie-sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trey Pendragon
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-01 00:00:00.000000000 Z
11
+ date: 2023-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -42,22 +42,16 @@ dependencies:
42
42
  name: valkyrie
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '2.1'
48
- - - "<"
45
+ - - "~>"
49
46
  - !ruby/object:Gem::Version
50
- version: '2.3'
47
+ version: '3.0'
51
48
  type: :runtime
52
49
  prerelease: false
53
50
  version_requirements: !ruby/object:Gem::Requirement
54
51
  requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: '2.1'
58
- - - "<"
52
+ - - "~>"
59
53
  - !ruby/object:Gem::Version
60
- version: '2.3'
54
+ version: '3.0'
61
55
  - !ruby/object:Gem::Dependency
62
56
  name: oj
63
57
  requirement: !ruby/object:Gem::Requirement
@@ -182,6 +176,7 @@ files:
182
176
  - ".rspec"
183
177
  - ".rubocop.yml"
184
178
  - ".travis.yml"
179
+ - CHANGELOG.md
185
180
  - Gemfile
186
181
  - LICENSE
187
182
  - README.md
@@ -203,7 +198,7 @@ files:
203
198
  homepage: https://github.com/samvera-labs/valkyrie-sequel
204
199
  licenses: []
205
200
  metadata: {}
206
- post_install_message:
201
+ post_install_message:
207
202
  rdoc_options: []
208
203
  require_paths:
209
204
  - lib
@@ -218,8 +213,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
213
  - !ruby/object:Gem::Version
219
214
  version: '0'
220
215
  requirements: []
221
- rubygems_version: 3.1.4
222
- signing_key:
216
+ rubygems_version: 3.1.6
217
+ signing_key:
223
218
  specification_version: 4
224
219
  summary: Valkyrie::MetadataAdapter for Postgres using Sequel.
225
220
  test_files: []