Module: Sequel::Plugins::Paperclip::InstanceMethods

Defined in:
lib/sequel_paperclip.rb

Instance Method Summary collapse

Instance Method Details

#after_destroyObject



152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/sequel_paperclip.rb', line 152

def after_destroy
  self.class.attachments.each_key do |name|
    send("#{name}=", nil)
  end

  if @attachment_instances
    @attachment_instances.each_value do |attachment|
      attachment.update_storage
    end
  end
  super
end

#after_saveObject



142
143
144
145
146
147
148
149
150
# File 'lib/sequel_paperclip.rb', line 142

def after_save
  if @attachment_instances
    @attachment_instances.each_value do |attachment|
      attachment.process
      attachment.update_storage
    end
  end
  super
end

#attachment_generate_basename(attachment) ⇒ Object



134
135
136
137
138
139
140
# File 'lib/sequel_paperclip.rb', line 134

def attachment_generate_basename(attachment)
  basename = send("#{attachment.name}_basename")
  while true
    new_basename = SecureRandom.hex(4).to_s
    return new_basename unless new_basename == basename
  end
end