Class: Asset

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/forge/app/models/asset.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for_drawer(params) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/forge/app/models/asset.rb', line 32

def self.for_drawer(params)
  unless params[:q].blank?
    assets = where("LOWER(assets.title) LIKE ? OR LOWER(tags.name) = ?", "%#{params[:q].downcase}%", params[:q].downcase).includes(:tags).references(:tags)
  else
    case params[:filter]
    when "images"
      assets = where("attachment_content_type LIKE ?", "%image%")
    when "documents"
      assets = where("attachment_content_type NOT LIKE ?", "%image%")
    else
      assets = self
    end
  end
  assets.limit(20).offset(params[:offset] || 0)
end

Instance Method Details

#dimensions(style = :original) ⇒ Object



27
28
29
30
# File 'lib/forge/app/models/asset.rb', line 27

def dimensions(style = :original)
  file = Paperclip.io_adapters.for(attachment.styles[style])
  Paperclip::Geometry.from_file(file).to_s.split('x')
end

#icon_pathObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/forge/app/models/asset.rb', line 48

def icon_path
  case attachment_content_type
  when /image/
    attachment.url(:thumbnail)
  when /audio/
    ActionController::Base.helpers.asset_path "forge/asset-icons/audio.jpg"
  when /excel/
    ActionController::Base.helpers.asset_path "forge/asset-icons/spreadsheet.jpg"
  when /pdf/
    ActionController::Base.helpers.asset_path "forge/asset-icons/pdf.jpg"
  else
    ActionController::Base.helpers.asset_path "forge/asset-icons/misc.jpg"
  end
end

#is_image?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/forge/app/models/asset.rb', line 23

def is_image?
  self.attachment_content_type =~ /image/
end

#list_titleObject



19
20
21
# File 'lib/forge/app/models/asset.rb', line 19

def list_title
  self.title.size > 16 ? self.title[0..15].strip + '...' : self.title
end

#swfupload_file!(data, filename) ⇒ Object



13
14
15
16
17
# File 'lib/forge/app/models/asset.rb', line 13

def swfupload_file!(data, filename)
  data.content_type = MIME::Types.type_for(data.original_filename).first.content_type rescue ""
  self.attachment = data
  self.title = filename
end