0.0
No commit activity in last 3 years
No release in over 3 years
TokyoTyrant Storage support for CarrierWave
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.9
~> 2.6

Runtime

>= 0.5.7
>= 1.6.7
 Project Readme

CarrierWave for TokyoTyrant

This gem adds support for tokyotyrant to CarrierWave

Installation

gem install carrierwave-tt

Or using Bundler, in Gemfile

gem 'rest-client'
gem 'carrierwave-tt'

Configuration

You'll need to configure the to use this in config/initializes/carrierwave.rb

CarrierWave.configure do |config|
  config.storage = :tt
  config.host = "http://localhost"
  config.port = 1978
  config.domain = 'localhost:1978'
end

And then in your uploader, set the storage to :tt:

class AvatarUploader < CarrierWave::Uploader::Base
  storage :tt
end

You can override configuration item in individual uploader like this:

class AvatarUploader < CarrierWave::Uploader::Base
  storage :tt

end

Configuration for use TT "Image Space"

# The defined image name versions to limit use
IMAGE_UPLOADER_ALLOW_IMAGE_VERSION_NAMES = %(320 640 800)
class ImageUploader < CarrierWave::Uploader::Base
  def store_dir
    "#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  def default_url
    # You can use FTP to upload a default image
    "#{Setting.upload_url}/blank.png#{version_name}"
  end

  # Override url method to implement with "Image Space"
  def url(version_name = "")
    @url ||= super({})
    version_name = version_name.to_s
    return @url if version_name.blank?
    if not version_name.in?(IMAGE_UPLOADER_ALLOW_IMAGE_VERSION_NAMES)
      # To protected version name using, when it not defined, this will be give an error message in development environment
      raise "ImageUploader version_name:#{version_name} not allow."
    end
    [@url,version_name].join("!") # thumb split with "!"
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end

  def filename
    if super.present?
      model.uploader_secure_token ||= SecureRandom.uuid.gsub("-","")
      Rails.logger.debug("(BaseUploader.filename) #{model.uploader_secure_token}")
      "#{model.uploader_secure_token}.#{file.extension.downcase}"
    end
  end
end