module RailsCom::AttachedOne

Public Instance Methods

attachment() click to toggle source
Calls superclass method
# File lib/rails_com/active_storage/attached_macros.rb, line 5
def attachment
  if super
    return super
  elsif defined?(@attachment)
    return @attachment
  end

  id = Com::BlobDefault.defaults["#{record.class.name}_#{name}"]
  if id
    begin
      @attachment = ActiveStorage::Attachment.new(record: record, name: name, blob: ActiveStorage::Blob.find(id))
    rescue ActiveRecord::RecordNotFound => e
      Rails.cache.delete('blob_default/default')
      retry
    end
  end
end
copy(from, from_name) click to toggle source
# File lib/rails_com/active_storage/attached_macros.rb, line 23
def copy(from, from_name)
  from_attachment = from.send "#{from_name}_attachment"
  record.send "create_#{name}_attachment", blob_id: from_attachment.blob_id
end