Class: Polypaperclip::Attachment

Inherits:
Paperclip::Attachment
  • Object
show all
Defined in:
lib/polypaperclip/attachment.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, instance, options = {}) ⇒ Attachment

Returns a new instance of Attachment.



4
5
6
7
8
9
10
11
12
13
14
15
# 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

Instance Method Details

#assign(uploaded_file) ⇒ Object



17
18
19
20
# 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) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/polypaperclip/attachment.rb', line 22

def instance_read(attr)
  if @instance.nil?
    nil
  else
    super
  end
end