valkyrie-sequel 2.1.0 → 2.2.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: 89a976b76238995b845b6b1d5d82cbf3a24afa1e92c795590f8045fa19a9295c
4
- data.tar.gz: 63c6b8e510197296ccc2b83428b00d40ab1f974b18f6db05c7dc28c62a955ec9
3
+ metadata.gz: cd54c1445fecd7ace70e07607d27da780bf9c47d6ac97c8681ab319908e1c36b
4
+ data.tar.gz: bce2c0e04e1c6aae88d0dfae9bcbb35fc0a4055c2223284526165fb71a34adde
5
5
  SHA512:
6
- metadata.gz: 71293e3bc4635ba2df250558612088e8dfcb2a7a77cc6923c27c1da7567b09e3c112d462ab0063985084f5a89c32a33ec4fd9aea2ff0120df74ce1583aad67c3
7
- data.tar.gz: 9ec49446c6f760ddba814e51154cde6e842d86fc76fbc81bf8b484f3478a2a23e1a27befca96239d41e0a14da561174b4e032902e8809143d861c7c00b4aa121
6
+ metadata.gz: e7b5a2524a6c10a7b49757ceb360560f2aac259c7376ff0abe51c456eaa8750b4dfdc9185dd692b1041a04bfaa649a047b240427ac4bc5be802fd7de4ebbff05
7
+ data.tar.gz: 789f2e2931f1c8ea9552124e1119a9582e2c703261782b1f4d242191391f01f5725994c70bb8d4653f5525b60bd8d0d7221177116eacde9862b05aa2e6ecc4a3
data/.circleci/config.yml CHANGED
@@ -3,9 +3,10 @@ version: 2
3
3
  jobs:
4
4
  build:
5
5
  docker:
6
- - image: circleci/ruby:2.4.6-node-browsers
6
+ - image: circleci/ruby:2.7.2-node-browsers
7
7
  environment:
8
8
  RAILS_ENV: test
9
+ BUNDLE_PATH: vendor/bundle
9
10
  DB_HOST: localhost
10
11
  DB_USERNAME: valkyrie_sequel
11
12
  DB_PASSWORD: ""
@@ -23,7 +24,7 @@ jobs:
23
24
  key: valkyrie-sequel-{{ checksum "Gemfile" }}
24
25
  - run: gem install bundler -v '~> 2.0'
25
26
  # Bundle install dependencies
26
- - run: bundle install --path vendor/bundle
27
+ - run: bundle install
27
28
  # Cache Dependencies
28
29
  - type: cache-save
29
30
  name: Store bundle cache
data/.rubocop.yml CHANGED
@@ -2,7 +2,6 @@ inherit_gem:
2
2
  bixby: bixby_default.yml
3
3
  AllCops:
4
4
  DisplayCopNames: true
5
- TargetRubyVersion: 2.3
6
5
  Exclude:
7
6
  - 'bin/*'
8
7
  - 'db/schema.rb'
@@ -24,3 +23,5 @@ Metrics/ParameterLists:
24
23
  RSpec/ExampleLength:
25
24
  Exclude:
26
25
  - 'spec/valkyrie/sequel/persister_spec.rb'
26
+ Rails/RakeEnvironment:
27
+ Enabled: false
@@ -48,16 +48,16 @@ module Valkyrie::Sequel
48
48
 
49
49
  private
50
50
 
51
- def host
52
- connection.opts[:host]
53
- end
51
+ def host
52
+ connection.opts[:host]
53
+ end
54
54
 
55
- def port
56
- connection.opts[:port]
57
- end
55
+ def port
56
+ connection.opts[:port]
57
+ end
58
58
 
59
- def database
60
- connection.opts[:database]
61
- end
59
+ def database
60
+ connection.opts[:database]
61
+ end
62
62
  end
63
63
  end
@@ -121,32 +121,32 @@ module Valkyrie::Sequel
121
121
 
122
122
  private
123
123
 
124
- def create_or_update(resource:, attributes:)
125
- attributes[:updated_at] = Time.now.utc
126
- 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
- end
124
+ def create_or_update(resource:, attributes:)
125
+ attributes[:updated_at] = Time.now.utc
126
+ 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
+ end
130
130
 
131
- def create(resource:, attributes:)
132
- attributes[:lock_version] = 0 if resource.optimistic_locking_enabled? && resources.columns.include?(:lock_version)
133
- Array(resources.returning.insert(attributes)).first
134
- end
131
+ def create(resource:, attributes:)
132
+ attributes[:lock_version] = 0 if resource.optimistic_locking_enabled? && resources.columns.include?(:lock_version)
133
+ Array(resources.returning.insert(attributes)).first
134
+ end
135
135
 
136
- def update(resource:, attributes:)
137
- relation = resources.where(id: attributes[:id])
138
- if resource.optimistic_locking_enabled?
139
- relation = relation.where(Sequel.function(:coalesce, :lock_version, 0) => attributes[:lock_version] || 0)
140
- attributes[:lock_version] = (Sequel.function(:coalesce, :lock_version, 0) + 1)
141
- end
142
- attributes.delete(:lock_version) if attributes[:lock_version].nil?
143
- output = relation.returning.update(attributes)
144
- raise Valkyrie::Persistence::StaleObjectError, "The object #{resource.id} has been updated by another process." if output.blank? && resource.optimistic_locking_enabled?
145
- Array(output).first
136
+ def update(resource:, attributes:)
137
+ relation = resources.where(id: attributes[:id])
138
+ if resource.optimistic_locking_enabled?
139
+ relation = relation.where(Sequel.function(:coalesce, :lock_version, 0) => attributes[:lock_version] || 0)
140
+ attributes[:lock_version] = (Sequel.function(:coalesce, :lock_version, 0) + 1)
146
141
  end
142
+ attributes.delete(:lock_version) if attributes[:lock_version].nil?
143
+ output = relation.returning.update(attributes)
144
+ raise Valkyrie::Persistence::StaleObjectError, "The object #{resource.id} has been updated by another process." if output.blank? && resource.optimistic_locking_enabled?
145
+ Array(output).first
146
+ end
147
147
 
148
- def exists?(id:)
149
- resources.select(1).first(id: id).nil?
150
- end
148
+ def exists?(id:)
149
+ resources.select(1).first(id: id).nil?
150
+ end
151
151
  end
152
152
  end
@@ -1,7 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
  module Valkyrie::Sequel
3
3
  class QueryService
4
+ # ACCEPTABLE_UUID is deprecated and unused.
5
+ # which IDs are acceptable is now decided by the database.
4
6
  ACCEPTABLE_UUID = %r{\A(\{)?([a-fA-F0-9]{4}-?){8}(?(1)\}|)\z}.freeze
7
+ DEFAULT_ID_TYPE = :uuid
8
+
5
9
  attr_reader :adapter
6
10
  delegate :resources, :resource_factory, :connection, to: :adapter
7
11
  def initialize(adapter:)
@@ -14,14 +18,27 @@ module Valkyrie::Sequel
14
18
  end
15
19
  end
16
20
 
21
+ # rubocop:disable Metrics/MethodLength
17
22
  def find_by(id:)
18
23
  id = Valkyrie::ID.new(id.to_s) if id.is_a?(String)
19
24
  validate_id(id)
20
- raise Valkyrie::Persistence::ObjectNotFoundError unless ACCEPTABLE_UUID.match?(id.to_s)
21
- attributes = resources.first(id: id.to_s)
25
+ attributes = nil
26
+ # Create a nested transaction so it can rollback to a non-essential
27
+ # savepoint if the query fails, not wrecking upstream transactions.
28
+ connection.transaction(savepoint: true) do
29
+ attributes = resources.first(id: id.to_s)
30
+ end
22
31
  raise Valkyrie::Persistence::ObjectNotFoundError unless attributes
23
32
  resource_factory.to_resource(object: attributes)
33
+ rescue Sequel::DatabaseError => err
34
+ case err.cause
35
+ when PG::InvalidTextRepresentation
36
+ raise Valkyrie::Persistence::ObjectNotFoundError
37
+ else
38
+ raise err
39
+ end
24
40
  end
41
+ # rubocop:enable Metrics/MethodLength
25
42
 
26
43
  def find_all_of_model(model:)
27
44
  resources.where(internal_resource: model.to_s).map do |attributes|
@@ -42,11 +59,8 @@ module Valkyrie::Sequel
42
59
  validate_id(id)
43
60
  id.to_s
44
61
  end
45
- ids = ids.select do |id|
46
- ACCEPTABLE_UUID.match?(id)
47
- end
48
62
 
49
- resources.where(id: ids).map do |attributes|
63
+ resources.where(Sequel.lit('(id::varchar) IN ?', ids)).map do |attributes|
50
64
  resource_factory.to_resource(object: attributes)
51
65
  end
52
66
  end
@@ -111,149 +125,149 @@ module Valkyrie::Sequel
111
125
 
112
126
  private
113
127
 
114
- # Generate the SQL query for retrieving member resources in PostgreSQL using a
115
- # resource ID as an argument.
116
- # @see https://guides.rubyonrails.org/active_record_querying.html#array-conditions
117
- # @note this uses a CROSS JOIN for all combinations of member IDs with the
118
- # IDs of their parents
119
- # @see https://www.postgresql.org/docs/current/static/queries-table-expressions.html#QUERIES-FROM
120
- # This also uses JSON functions in order to retrieve JSON property values
121
- # @see https://www.postgresql.org/docs/current/static/functions-json.html
122
- # @return [String]
123
- def find_members_query
124
- <<-SQL
128
+ # Generate the SQL query for retrieving member resources in PostgreSQL using a
129
+ # resource ID as an argument.
130
+ # @see https://guides.rubyonrails.org/active_record_querying.html#array-conditions
131
+ # @note this uses a CROSS JOIN for all combinations of member IDs with the
132
+ # IDs of their parents
133
+ # @see https://www.postgresql.org/docs/current/static/queries-table-expressions.html#QUERIES-FROM
134
+ # This also uses JSON functions in order to retrieve JSON property values
135
+ # @see https://www.postgresql.org/docs/current/static/functions-json.html
136
+ # @return [String]
137
+ def find_members_query
138
+ <<-SQL
125
139
  SELECT member.* FROM orm_resources a,
126
140
  jsonb_array_elements(a.metadata->'member_ids') WITH ORDINALITY AS b(member, member_pos)
127
141
  JOIN orm_resources member ON (b.member->>'id')::#{id_type} = member.id WHERE a.id = ?
128
142
  ORDER BY b.member_pos
129
143
  SQL
130
- end
144
+ end
131
145
 
132
- # Generate the SQL query for retrieving member resources in PostgreSQL using a
133
- # resource ID and resource type as arguments.
134
- # @see https://guides.rubyonrails.org/active_record_querying.html#array-conditions
135
- # @note this uses a CROSS JOIN for all combinations of member IDs with the
136
- # IDs of their parents
137
- # @see https://www.postgresql.org/docs/current/static/queries-table-expressions.html#QUERIES-FROM
138
- # This also uses JSON functions in order to retrieve JSON property values
139
- # @see https://www.postgresql.org/docs/current/static/functions-json.html
140
- # @return [String]
141
- def find_members_with_type_query
142
- <<-SQL
146
+ # Generate the SQL query for retrieving member resources in PostgreSQL using a
147
+ # resource ID and resource type as arguments.
148
+ # @see https://guides.rubyonrails.org/active_record_querying.html#array-conditions
149
+ # @note this uses a CROSS JOIN for all combinations of member IDs with the
150
+ # IDs of their parents
151
+ # @see https://www.postgresql.org/docs/current/static/queries-table-expressions.html#QUERIES-FROM
152
+ # This also uses JSON functions in order to retrieve JSON property values
153
+ # @see https://www.postgresql.org/docs/current/static/functions-json.html
154
+ # @return [String]
155
+ def find_members_with_type_query
156
+ <<-SQL
143
157
  SELECT member.* FROM orm_resources a,
144
158
  jsonb_array_elements(a.metadata->'member_ids') WITH ORDINALITY AS b(member, member_pos)
145
159
  JOIN orm_resources member ON (b.member->>'id')::#{id_type} = member.id WHERE a.id = ?
146
160
  AND member.internal_resource = ?
147
161
  ORDER BY b.member_pos
148
162
  SQL
149
- end
163
+ end
150
164
 
151
- # Generate the SQL query for retrieving member resources in PostgreSQL using a
152
- # JSON object literal as an argument (e. g. { "alternate_ids": [{"id": "d6e88f80-41b3-4dbf-a2a0-cd79e20f6d10"}] }).
153
- # @see https://guides.rubyonrails.org/active_record_querying.html#array-conditions
154
- # This uses JSON functions in order to retrieve JSON property values
155
- # @see https://www.postgresql.org/docs/current/static/functions-json.html
156
- # @return [String]
157
- def find_inverse_references_query
158
- <<-SQL
165
+ # Generate the SQL query for retrieving member resources in PostgreSQL using a
166
+ # JSON object literal as an argument (e. g. { "alternate_ids": [{"id": "d6e88f80-41b3-4dbf-a2a0-cd79e20f6d10"}] }).
167
+ # @see https://guides.rubyonrails.org/active_record_querying.html#array-conditions
168
+ # This uses JSON functions in order to retrieve JSON property values
169
+ # @see https://www.postgresql.org/docs/current/static/functions-json.html
170
+ # @return [String]
171
+ def find_inverse_references_query
172
+ <<-SQL
159
173
  SELECT * FROM orm_resources WHERE
160
174
  metadata @> ?
161
175
  SQL
162
- end
176
+ end
163
177
 
164
- def find_inverse_references_with_model_query
165
- <<-SQL
178
+ def find_inverse_references_with_model_query
179
+ <<-SQL
166
180
  SELECT * FROM orm_resources WHERE
167
181
  metadata @> ?
168
182
  AND internal_resource = ?
169
183
  SQL
170
- end
184
+ end
171
185
 
172
- # Generate the SQL query for retrieving member resources in PostgreSQL using a
173
- # JSON object literal and resource ID as arguments.
174
- # @see https://guides.rubyonrails.org/active_record_querying.html#array-conditions
175
- # @note this uses a CROSS JOIN for all combinations of member IDs with the
176
- # IDs of their parents
177
- # @see https://www.postgresql.org/docs/current/static/queries-table-expressions.html#QUERIES-FROM
178
- # This also uses JSON functions in order to retrieve JSON property values
179
- # @see https://www.postgresql.org/docs/current/static/functions-json.html
180
- # @return [String]
181
- def find_references_query
182
- <<-SQL
186
+ # Generate the SQL query for retrieving member resources in PostgreSQL using a
187
+ # JSON object literal and resource ID as arguments.
188
+ # @see https://guides.rubyonrails.org/active_record_querying.html#array-conditions
189
+ # @note this uses a CROSS JOIN for all combinations of member IDs with the
190
+ # IDs of their parents
191
+ # @see https://www.postgresql.org/docs/current/static/queries-table-expressions.html#QUERIES-FROM
192
+ # This also uses JSON functions in order to retrieve JSON property values
193
+ # @see https://www.postgresql.org/docs/current/static/functions-json.html
194
+ # @return [String]
195
+ def find_references_query
196
+ <<-SQL
183
197
  SELECT DISTINCT member.* FROM orm_resources a,
184
198
  jsonb_array_elements(a.metadata->?) AS b(member)
185
199
  JOIN orm_resources member ON (b.member->>'id')::#{id_type} = member.id WHERE a.id = ?
186
200
  SQL
187
- end
201
+ end
188
202
 
189
- def find_references_with_type_query
190
- <<-SQL
203
+ def find_references_with_type_query
204
+ <<-SQL
191
205
  SELECT DISTINCT member.* FROM orm_resources a,
192
206
  jsonb_array_elements(a.metadata->?) AS b(member)
193
207
  JOIN orm_resources member ON (b.member->>'id')::#{id_type} = member.id WHERE a.id = ?
194
208
  AND member.internal_resource = ?
195
209
  SQL
196
- end
210
+ end
197
211
 
198
- def find_ordered_references_query
199
- <<-SQL
212
+ def find_ordered_references_query
213
+ <<-SQL
200
214
  SELECT member.* FROM orm_resources a,
201
215
  jsonb_array_elements(a.metadata->?) WITH ORDINALITY AS b(member, member_pos)
202
216
  JOIN orm_resources member ON (b.member->>'id')::#{id_type} = member.id WHERE a.id = ?
203
217
  ORDER BY b.member_pos
204
218
  SQL
205
- end
219
+ end
206
220
 
207
- def find_ordered_references_with_type_query
208
- <<-SQL
221
+ def find_ordered_references_with_type_query
222
+ <<-SQL
209
223
  SELECT member.* FROM orm_resources a,
210
224
  jsonb_array_elements(a.metadata->?) WITH ORDINALITY AS b(member, member_pos)
211
225
  JOIN orm_resources member ON (b.member->>'id')::#{id_type} = member.id WHERE a.id = ?
212
226
  AND member.internal_resource = ?
213
227
  ORDER BY b.member_pos
214
228
  SQL
215
- end
229
+ end
216
230
 
217
- # Accesses the data type in PostgreSQL used for the primary key
218
- # (For example, a UUID)
219
- # @see https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaCache.html#method-i-columns_hash
220
- # @return [Symbol]
221
- def id_type
222
- @id_type ||= :uuid
223
- end
231
+ # Accesses the data type in PostgreSQL used for the primary key
232
+ # (For example, a UUID)
233
+ # @see https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaCache.html#method-i-columns_hash
234
+ # @return [Symbol]
235
+ def id_type
236
+ @id_type ||= DEFAULT_ID_TYPE
237
+ end
224
238
 
225
- # Determines whether or not an Object is a Valkyrie ID
226
- # @param [Object] id
227
- # @raise [ArgumentError]
228
- def validate_id(id)
229
- raise ArgumentError, 'id must be a Valkyrie::ID' unless id.is_a? Valkyrie::ID
230
- end
239
+ # Determines whether or not an Object is a Valkyrie ID
240
+ # @param [Object] id
241
+ # @raise [ArgumentError]
242
+ def validate_id(id)
243
+ raise ArgumentError, 'id must be a Valkyrie::ID' unless id.is_a? Valkyrie::ID
244
+ end
231
245
 
232
- # Determines whether or not a resource has been persisted
233
- # @param [Object] resource
234
- # @raise [ArgumentError]
235
- def ensure_persisted(resource)
236
- raise ArgumentError, 'resource is not saved' unless resource.persisted?
237
- end
246
+ # Determines whether or not a resource has been persisted
247
+ # @param [Object] resource
248
+ # @raise [ArgumentError]
249
+ def ensure_persisted(resource)
250
+ raise ArgumentError, 'resource is not saved' unless resource.persisted?
251
+ end
238
252
 
239
- def ordered_property?(resource:, property:)
240
- resource.ordered_attribute?(property)
241
- end
253
+ def ordered_property?(resource:, property:)
254
+ resource.ordered_attribute?(property)
255
+ end
242
256
 
243
- def find_ordered_references_by(resource:, property:, model: nil)
244
- if model
245
- run_query(find_ordered_references_with_type_query, property.to_s, resource.id.to_s, model.to_s)
246
- else
247
- run_query(find_ordered_references_query, property.to_s, resource.id.to_s)
248
- end
257
+ def find_ordered_references_by(resource:, property:, model: nil)
258
+ if model
259
+ run_query(find_ordered_references_with_type_query, property.to_s, resource.id.to_s, model.to_s)
260
+ else
261
+ run_query(find_ordered_references_query, property.to_s, resource.id.to_s)
249
262
  end
263
+ end
250
264
 
251
- def find_unordered_references_by(resource:, property:, model: nil)
252
- if model
253
- run_query(find_references_with_type_query, property.to_s, resource.id.to_s, model.to_s)
254
- else
255
- run_query(find_references_query, property.to_s, resource.id.to_s)
256
- end
265
+ def find_unordered_references_by(resource:, property:, model: nil)
266
+ if model
267
+ run_query(find_references_with_type_query, property.to_s, resource.id.to_s, model.to_s)
268
+ else
269
+ run_query(find_references_query, property.to_s, resource.id.to_s)
257
270
  end
271
+ end
258
272
  end
259
273
  end
@@ -13,48 +13,48 @@ module Valkyrie::Sequel
13
13
 
14
14
  private
15
15
 
16
- # Construct a new Valkyrie Resource using the attributes retrieved from the database
17
- # @return [Valkyrie::Resource]
18
- def resource
19
- resource_klass.new(
20
- attributes.merge(
21
- new_record: false,
22
- Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK => lock_token
23
- )
16
+ # Construct a new Valkyrie Resource using the attributes retrieved from the database
17
+ # @return [Valkyrie::Resource]
18
+ def resource
19
+ resource_klass.new(
20
+ attributes.merge(
21
+ new_record: false,
22
+ Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK => lock_token
24
23
  )
25
- end
26
-
27
- # Construct the optimistic lock token using the adapter and lock version for the Resource
28
- # @return [Valkyrie::Persistence::OptimisticLockToken]
29
- def lock_token
30
- return nil unless object[:lock_version].present?
31
- @lock_token ||=
32
- Valkyrie::Persistence::OptimisticLockToken.new(
33
- adapter_id: resource_factory.adapter_id,
34
- token: object[:lock_version]
35
- )
36
- end
37
-
38
- # Retrieve the Class used to construct the Valkyrie Resource
39
- # @return [Class]
40
- def resource_klass
41
- internal_resource.constantize
42
- end
43
-
44
- # Access the String for the Valkyrie Resource type within the attributes
45
- # @return [String]
46
- def internal_resource
47
- attributes[:internal_resource]
48
- end
49
-
50
- def attributes
51
- @attributes ||= object.except(:metadata).merge(rdf_metadata).symbolize_keys
52
- end
53
-
54
- # Generate a Hash derived from Valkyrie Resource metadata encoded in the RDF
55
- # @return [Hash]
56
- def rdf_metadata
57
- @rdf_metadata ||= Valkyrie::Persistence::Shared::JSONValueMapper.new(object[:metadata]).result
58
- end
24
+ )
25
+ end
26
+
27
+ # Construct the optimistic lock token using the adapter and lock version for the Resource
28
+ # @return [Valkyrie::Persistence::OptimisticLockToken]
29
+ def lock_token
30
+ return nil if object[:lock_version].blank?
31
+ @lock_token ||=
32
+ Valkyrie::Persistence::OptimisticLockToken.new(
33
+ adapter_id: resource_factory.adapter_id,
34
+ token: object[:lock_version]
35
+ )
36
+ end
37
+
38
+ # Retrieve the Class used to construct the Valkyrie Resource
39
+ # @return [Class]
40
+ def resource_klass
41
+ internal_resource.constantize
42
+ end
43
+
44
+ # Access the String for the Valkyrie Resource type within the attributes
45
+ # @return [String]
46
+ def internal_resource
47
+ attributes[:internal_resource]
48
+ end
49
+
50
+ def attributes
51
+ @attributes ||= object.except(:metadata).merge(rdf_metadata).symbolize_keys
52
+ end
53
+
54
+ # Generate a Hash derived from Valkyrie Resource metadata encoded in the RDF
55
+ # @return [Hash]
56
+ def rdf_metadata
57
+ @rdf_metadata ||= Valkyrie::Persistence::Shared::JSONValueMapper.new(object[:metadata]).result
58
+ end
59
59
  end
60
60
  end
@@ -8,7 +8,7 @@ module Valkyrie::Sequel
8
8
  :internal_resource
9
9
  ].freeze
10
10
 
11
- BLACKLIST_TERMS = [
11
+ DISALLOWED_TERMS = [
12
12
  :new_record
13
13
  ].freeze
14
14
 
@@ -23,53 +23,52 @@ module Valkyrie::Sequel
23
23
  def convert!
24
24
  output = database_hash
25
25
  output[:id] = resource.id.to_s if resource.id
26
- output.delete(:id) unless !output[:id] || QueryService::ACCEPTABLE_UUID.match?(output[:id].to_s)
27
26
  process_lock_token(output)
28
27
  output
29
28
  end
30
29
 
31
30
  private
32
31
 
33
- # Retrieves the optimistic lock token from the Valkyrie attribute value and
34
- # sets it to the lock_version on ORM resource
35
- # @see https://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html
36
- # @param [ORM::Resource] orm_object
37
- def process_lock_token(orm_object)
38
- return unless resource.respond_to?(Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK)
39
- postgres_token = (resource[Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK] || []).find do |token|
40
- token.adapter_id == resource_factory.adapter_id
41
- end
42
- return unless postgres_token
43
- orm_object[:lock_version] = postgres_token.token
44
- end
45
-
46
- def database_hash
47
- resource_hash.select do |k, _v|
48
- PRIMARY_TERMS.include?(k)
49
- end.compact.merge(
50
- metadata: ::Sequel.pg_json(metadata_hash)
51
- )
32
+ # Retrieves the optimistic lock token from the Valkyrie attribute value and
33
+ # sets it to the lock_version on ORM resource
34
+ # @see https://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html
35
+ # @param [ORM::Resource] orm_object
36
+ def process_lock_token(orm_object)
37
+ return unless resource.respond_to?(Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK)
38
+ postgres_token = (resource[Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK] || []).find do |token|
39
+ token.adapter_id == resource_factory.adapter_id
52
40
  end
41
+ return unless postgres_token
42
+ orm_object[:lock_version] = postgres_token.token
43
+ end
53
44
 
54
- def resource_hash
55
- @resource_hash ||= resource.__attributes__
56
- end
45
+ def database_hash
46
+ resource_hash.select do |k, _v|
47
+ PRIMARY_TERMS.include?(k)
48
+ end.compact.merge(
49
+ metadata: ::Sequel.pg_json(metadata_hash)
50
+ )
51
+ end
57
52
 
58
- # Convert attributes to all be arrays to better enable querying and
59
- # "changing of minds" later on.
60
- # @return [Hash]
61
- def metadata_hash
62
- Hash[
63
- selected_resource_attributes.compact.map do |k, v|
64
- [k, Array.wrap(v)]
65
- end
66
- ]
67
- end
53
+ def resource_hash
54
+ @resource_hash ||= resource.__attributes__
55
+ end
68
56
 
69
- def selected_resource_attributes
70
- resource_hash.select do |k, _v|
71
- !PRIMARY_TERMS.include?(k) && !BLACKLIST_TERMS.include?(k)
57
+ # Convert attributes to all be arrays to better enable querying and
58
+ # "changing of minds" later on.
59
+ # @return [Hash]
60
+ def metadata_hash
61
+ Hash[
62
+ selected_resource_attributes.compact.map do |k, v|
63
+ [k, Array.wrap(v)]
72
64
  end
65
+ ]
66
+ end
67
+
68
+ def selected_resource_attributes
69
+ resource_hash.select do |k, _v|
70
+ !PRIMARY_TERMS.include?(k) && !DISALLOWED_TERMS.include?(k)
73
71
  end
72
+ end
74
73
  end
75
74
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Valkyrie
3
3
  module Sequel
4
- VERSION = "2.1.0"
4
+ VERSION = "2.2.0"
5
5
  end
6
6
  end
@@ -20,16 +20,15 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_dependency "sequel"
24
- spec.add_dependency "sequel_pg"
23
+ spec.add_dependency "sequel", "~> 5.0"
24
+ spec.add_dependency "sequel_pg", "~> 1.0"
25
25
  spec.add_dependency "valkyrie", '~> 2.1.0'
26
- spec.add_dependency "oj"
26
+ spec.add_dependency "oj", "~> 3.0"
27
27
  spec.add_development_dependency "bundler", "~> 2.0"
28
28
  spec.add_development_dependency "rake"
29
29
  spec.add_development_dependency "rspec", "~> 3.0"
30
30
  spec.add_development_dependency "bixby"
31
31
  spec.add_development_dependency "pry-byebug"
32
- spec.add_development_dependency "database_cleaner"
33
- spec.add_development_dependency "coveralls"
32
+ spec.add_development_dependency "database_cleaner", "< 2"
34
33
  spec.add_development_dependency "simplecov"
35
34
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valkyrie-sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.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: 2020-03-10 00:00:00.000000000 Z
11
+ date: 2021-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sequel_pg
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: valkyrie
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: oj
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '3.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '3.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -140,30 +140,16 @@ dependencies:
140
140
  name: database_cleaner
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: coveralls
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
143
+ - - "<"
158
144
  - !ruby/object:Gem::Version
159
- version: '0'
145
+ version: '2'
160
146
  type: :development
161
147
  prerelease: false
162
148
  version_requirements: !ruby/object:Gem::Requirement
163
149
  requirements:
164
- - - ">="
150
+ - - "<"
165
151
  - !ruby/object:Gem::Version
166
- version: '0'
152
+ version: '2'
167
153
  - !ruby/object:Gem::Dependency
168
154
  name: simplecov
169
155
  requirement: !ruby/object:Gem::Requirement
@@ -211,7 +197,7 @@ files:
211
197
  homepage: https://github.com/samvera-labs/valkyrie-sequel
212
198
  licenses: []
213
199
  metadata: {}
214
- post_install_message:
200
+ post_install_message:
215
201
  rdoc_options: []
216
202
  require_paths:
217
203
  - lib
@@ -226,8 +212,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
212
  - !ruby/object:Gem::Version
227
213
  version: '0'
228
214
  requirements: []
229
- rubygems_version: 3.0.3
230
- signing_key:
215
+ rubygems_version: 3.1.4
216
+ signing_key:
231
217
  specification_version: 4
232
218
  summary: Valkyrie::MetadataAdapter for Postgres using Sequel.
233
219
  test_files: []