module Shrine::Plugins::Sequel::AttacherMethods
The _persistence plugin uses sequel_persist
, sequel_reload
and sequel?
to implement the following methods:
* Attacher#persist * Attacher#atomic_persist * Attacher#atomic_promote
Private Instance Methods
Returns whether the record is a Sequel
model. Used by the _persistence plugin.
# File lib/shrine/plugins/sequel.rb, line 132 def sequel? record.is_a?(::Sequel::Model) end
Deletes attached files. Called after model destroy.
# File lib/shrine/plugins/sequel.rb, line 104 def sequel_after_destroy record.db.after_commit do destroy_attached end end
Finalizes attachment and persists changes. Called after model save.
# File lib/shrine/plugins/sequel.rb, line 96 def sequel_after_save record.db.after_commit do finalize persist end end
Calls Attacher#save
. Called before model save.
# File lib/shrine/plugins/sequel.rb, line 91 def sequel_before_save save end
Returns true if the data attribute represents a JSON or JSONB column. Used by the _persistence plugin to determine whether serialization should be skipped.
# File lib/shrine/plugins/sequel.rb, line 125 def sequel_hash_attribute? column = record.class.db_schema[attribute] column && [:json, :jsonb].include?(column[:type]) end
Saves changes to the model instance, skipping validations. Used by the _persistence plugin.
# File lib/shrine/plugins/sequel.rb, line 112 def sequel_persist record.save_changes(validate: false) end
Locks the database row and yields the reloaded record. Used by the _persistence plugin.
# File lib/shrine/plugins/sequel.rb, line 118 def sequel_reload record.db.transaction { yield record.dup.lock! } end
Adds file validation errors to the model. Called on model validation.
# File lib/shrine/plugins/sequel.rb, line 82 def sequel_validate return unless respond_to?(:errors) errors.each do |message| record.errors.add(name, *message) end end