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

sequel?() click to toggle source

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
sequel_after_destroy() click to toggle source

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
sequel_after_save() click to toggle source

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
sequel_before_save() click to toggle source

Calls Attacher#save. Called before model save.

# File lib/shrine/plugins/sequel.rb, line 91
def sequel_before_save
  save
end
sequel_hash_attribute?() click to toggle source

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
sequel_persist() click to toggle source

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
sequel_reload() { |dup.lock!| ... } click to toggle source

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
sequel_validate() click to toggle source

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