Sha256: e7b46e51a5241a29f6e6c2c51b3ce196b8c1910dd7bb9ed116087ad4050e3ab2

Contents?: true

Size: 1.02 KB

Versions: 36

Compression:

Stored size: 1.02 KB

Contents

class Downloadable < ActiveRecord::Base
  belongs_to :index
  attr_accessible :name, :description, :asset, :asset_file_name, :asset_content_type, :asset_file_size

  validates_presence_of :name, :asset

  include ActsAsPrioritizable
  acts_as_prioritizable("index", "assets")

  has_attached_file :asset,
    :storage => :s3,
    :s3_credentials => Rails.root.join("config", "s3.yml"),
    :bucket => APP_CONFIG[:bucket_name],
    :path => "/downloadables/#{Rails.env}/:id/:filename"

  before_post_process :transliterate_file_name

  def thumb
    asset.url(:thumb)
  end

  def transliterate(str)
    s = Iconv.iconv('ascii//ignore//translit', 'utf-8', str).to_s
    s.downcase!
    s.gsub!(/'/, '')
    s.gsub!(/[^A-Za-z0-9]+/, ' ')
    s.strip!
    s.gsub!(/\ +/, '-')
    s
  end

  def transliterate_file_name
    extension = File.extname(asset_file_name).gsub(/^\.+/, '')
    filename = asset_file_name.gsub(/\.#{extension}$/, '')
    self.asset.instance_write(:file_name, "#{transliterate(filename)}.#{transliterate(extension)}")
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
sbdevcore-0.3.10 app/models/downloadable.rb
sbdevcore-0.3.9 app/models/downloadable.rb
sbdevcore-0.3.8 app/models/downloadable.rb
sbdevcore-0.3.7 app/models/downloadable.rb
sbdevcore-0.3.6 app/models/downloadable.rb
sbdevcore-0.3.5 app/models/downloadable.rb
sbdevcore-0.3.4 app/models/downloadable.rb
sbdevcore-0.3.3 app/models/downloadable.rb
sbdevcore-0.3.2 app/models/downloadable.rb
sbdevcore-0.3.1 app/models/downloadable.rb
sbdevcore-0.3.0 app/models/downloadable.rb
sbdevcore-0.2.26 app/models/downloadable.rb
sbdevcore-0.2.25 app/models/downloadable.rb
sbdevcore-0.2.24 app/models/downloadable.rb
sbdevcore-0.2.23 app/models/downloadable.rb
sbdevcore-0.2.22 app/models/downloadable.rb
sbdevcore-0.2.21 app/models/downloadable.rb
sbdevcore-0.2.20 app/models/downloadable.rb
sbdevcore-0.2.19 app/models/downloadable.rb
sbdevcore-0.2.18 app/models/downloadable.rb