valkyrie-sequel 1.0.0 → 1.1.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
  SHA1:
3
- metadata.gz: 147de175c6560bcb1836553dd0c5c3e94908c5f8
4
- data.tar.gz: e48b68150de3a5ed8efb8ac4064866db769227ee
3
+ metadata.gz: d6e9fe995f047640837186d5468d2c13c1a4bde5
4
+ data.tar.gz: 2802d8cdee2d9bc7a029be53053a8d2df0e56358
5
5
  SHA512:
6
- metadata.gz: 546160cf2ab0d62a4e2196bc8f390510999cc8e2e9e74e6aa3f483eec6c2f236b45103361d37c31f98d84cf4a45fbf4dd98cbe6cf389ad20aefe594eb7326a6f
7
- data.tar.gz: 396c775f741c4d972e372c5400cd9f23236dac76c983e5d3183553726c745e3bf30be4dbf4dbb17e456d1ee29fbc8eaa551d0e3dc8f7d929e5bddd0629ab688c
6
+ metadata.gz: bb9d0289ef5b574b75447c06531416f306db195ad9a3e213cba51ab4671bd3cf62504a107f5647f6a6f2262b45805d832ad88bfbbf5252d3b953d2a2963dd743
7
+ data.tar.gz: 9d38118312e0e27e71c8035b40eabc23c15719bbe33b87d4deb2e99fc1347f95384e457ee1480ebbab71d6072eff3750281dc96b8a8fc933ca6639365da27c13
data/.rubocop.yml CHANGED
@@ -20,3 +20,6 @@ Metrics/ClassLength:
20
20
  Metrics/ParameterLists:
21
21
  Exclude:
22
22
  - 'lib/valkyrie/sequel/metadata_adapter.rb'
23
+ RSpec/ExampleLength:
24
+ Exclude:
25
+ - 'spec/valkyrie/sequel/persister_spec.rb'
@@ -61,7 +61,7 @@ module Valkyrie::Sequel
61
61
  resources.returning.insert_conflict(
62
62
  target: :id,
63
63
  update: update_branches,
64
- update_where: { Sequel[:orm_resources][:lock_version] => Sequel[:excluded][:lock_version] }
64
+ update_where: { Sequel.function(:coalesce, Sequel[:orm_resources][:lock_version], 0) => Sequel[:excluded][:lock_version] }
65
65
  )
66
66
  end
67
67
 
@@ -69,7 +69,7 @@ module Valkyrie::Sequel
69
69
  {
70
70
  metadata: Sequel[:excluded][:metadata],
71
71
  internal_resource: Sequel[:excluded][:internal_resource],
72
- lock_version: Sequel[:excluded][:lock_version] + 1,
72
+ lock_version: Sequel.function(:coalesce, Sequel[:excluded][:lock_version], 0) + 1,
73
73
  created_at: Sequel[:excluded][:created_at],
74
74
  updated_at: Time.now.utc
75
75
  }
@@ -109,6 +109,7 @@ module Valkyrie::Sequel
109
109
  end
110
110
  end
111
111
  end
112
+
112
113
  def delete(resource:)
113
114
  resources.where(id: resource.id.to_s).delete
114
115
  resource
@@ -135,8 +136,8 @@ module Valkyrie::Sequel
135
136
  def update(resource:, attributes:)
136
137
  relation = resources.where(id: attributes[:id])
137
138
  if resource.optimistic_locking_enabled?
138
- relation = relation.where(lock_version: attributes[:lock_version]) if attributes[:lock_version]
139
- attributes[:lock_version] = (Sequel[:lock_version] + 1)
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)
140
141
  end
141
142
  attributes.delete(:lock_version) if attributes[:lock_version].nil?
142
143
  output = relation.returning.update(attributes)
@@ -27,6 +27,7 @@ module Valkyrie::Sequel
27
27
  # Construct the optimistic lock token using the adapter and lock version for the Resource
28
28
  # @return [Valkyrie::Persistence::OptimisticLockToken]
29
29
  def lock_token
30
+ return nil unless object[:lock_version].present?
30
31
  @lock_token ||=
31
32
  Valkyrie::Persistence::OptimisticLockToken.new(
32
33
  adapter_id: resource_factory.adapter_id,
@@ -25,7 +25,7 @@ module Valkyrie::Sequel
25
25
  # @param [ORM::Resource] orm_object
26
26
  def process_lock_token(orm_object)
27
27
  return unless resource.respond_to?(Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK)
28
- postgres_token = resource[Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK].find do |token|
28
+ postgres_token = (resource[Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK] || []).find do |token|
29
29
  token.adapter_id == resource_factory.adapter_id
30
30
  end
31
31
  return unless postgres_token
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Valkyrie
3
3
  module Sequel
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
6
6
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_dependency "sequel"
25
25
  spec.add_dependency "sequel_pg"
26
- spec.add_dependency "valkyrie", "~> 1.5.0.RC1"
26
+ spec.add_dependency "valkyrie", '>= 1.5.0', '< 3.0.0'
27
27
  spec.add_dependency "oj"
28
28
  spec.add_development_dependency "bundler", "~> 1.16"
29
29
  spec.add_development_dependency "rake", "~> 10.0"
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: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trey Pendragon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-11 00:00:00.000000000 Z
11
+ date: 2019-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -42,16 +42,22 @@ dependencies:
42
42
  name: valkyrie
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.5.0
48
+ - - "<"
46
49
  - !ruby/object:Gem::Version
47
- version: 1.5.0.RC1
50
+ version: 3.0.0
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
- - - "~>"
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 1.5.0
58
+ - - "<"
53
59
  - !ruby/object:Gem::Version
54
- version: 1.5.0.RC1
60
+ version: 3.0.0
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: oj
57
63
  requirement: !ruby/object:Gem::Requirement