class Polypaperclip::Attachment

Public Class Methods

new(name, instance, options = {}) click to toggle source
Calls superclass method
# File lib/polypaperclip/attachment.rb, line 4
def initialize(name, instance, options = {})
  super
  
  #retain the actual object in the attachment instance
  @poly_instance = instance
  @poly_name = name

  #cheat instance to reflect the polymorphic attachment
  #this sort of tricks paperclip in order for it to the right things
  @instance = instance.send("#{name}_attachment")
  @name = "attachment"
end

Public Instance Methods

assign(uploaded_file) click to toggle source
Calls superclass method
# File lib/polypaperclip/attachment.rb, line 17
def assign(uploaded_file)
  build_instance if @instance.nil? #we want to replace
  super
end
instance_read(attr) click to toggle source
Calls superclass method
# File lib/polypaperclip/attachment.rb, line 22
def instance_read(attr)
  if @instance.nil?
    nil
  else
    super
  end
end

Protected Instance Methods

build_instance() click to toggle source
# File lib/polypaperclip/attachment.rb, line 31
def build_instance
  @instance ||= @poly_instance.send("build_#{@poly_name}_attachment")
  @instance.attachment_type = @poly_name.to_s
  @instance.attachable = @poly_instance
  @instance
end