class Attach::Attachment

Attributes

binary[W]

This will be the ActionDispatch::UploadedFile object which be diseminated by the class on save.

Public Class Methods

for(role) click to toggle source

Return the attachment for a given role

# File lib/attach/attachment.rb, line 63
def self.for(role)
  self.where(:role => role).first
end

Public Instance Methods

add_child(role, &block) click to toggle source

Add a child attachment

# File lib/attach/attachment.rb, line 101
def add_child(role, &block)
  attachment = self.children.build
  attachment.role = role
  attachment.owner = self.owner
  attachment.file_name = self.file_name
  attachment.file_type = self.file_type
  attachment.disposition = self.disposition
  attachment.cache_type = self.cache_type
  attachment.cache_max_age = self.cache_max_age
  attachment.type = self.type
  block.call(attachment)
  attachment.save!
end
binary() click to toggle source

Return the binary data for this attachment

# File lib/attach/attachment.rb, line 68
def binary
  @binary ||= persisted? ? Attach.backend.read(self) : nil
  @binary == :nil ? nil : @binary
end
child(role) click to toggle source

Return a child process

# File lib/attach/attachment.rb, line 89
def child(role)
  @cached_children ||= {}
  @cached_children[role.to_sym] ||= self.children.where(:role => role).first || :nil
  @cached_children[role.to_sym] == :nil ? nil : @cached_children[role.to_sym]
end
image?() click to toggle source

Is the attachment an image?

# File lib/attach/attachment.rb, line 79
def image?
  file_type =~ /\Aimage\//
end
processor() click to toggle source

Return a processor for this attachment

# File lib/attach/attachment.rb, line 84
def processor
  @processor ||= Processor.new(self)
end
try(role) click to toggle source

Try to return a given otherwise revert to the parent

# File lib/attach/attachment.rb, line 96
def try(role)
  child(role) || self
end
url() click to toggle source

Return the path to the attachment

# File lib/attach/attachment.rb, line 74
def url
  Attach.backend.url(self)
end