Skip to content

Commit

Permalink
Support new Valkyrie.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpendragon committed Jul 28, 2021
1 parent 2e6932e commit 219b958
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in valkyrie-sequel.gemspec
gemspec
gem "valkyrie", branch: "837-persisters-should-error", github: "samvera/valkyrie"
10 changes: 7 additions & 3 deletions lib/valkyrie/sequel/persister.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@ def wipe!
def create_or_update(resource:, attributes:)
attributes[:updated_at] = Time.now.utc
attributes[:created_at] ||= Time.now.utc
return create(resource: resource, attributes: attributes) unless resource.persisted? && !exists?(id: attributes[:id])
update(resource: resource, attributes: attributes)
if resource.persisted?
raise Valkyrie::Persistence::ObjectNotFoundError, "The object #{resource.id} is previously persisted but not found at save time." unless exists?(id: attributes[:id])
update(resource: resource, attributes: attributes)
else
create(resource: resource, attributes: attributes) unless resource.persisted? && !exists?(id: attributes[:id])
end
end

def create(resource:, attributes:)
Expand All @@ -146,7 +150,7 @@ def update(resource:, attributes:)
end

def exists?(id:)
resources.select(1).first(id: id).nil?
!resources.select(1).first(id: id).nil?
end
end
end

0 comments on commit 219b958

Please sign in to comment.