module Paperclip::Storage::Aliyun

Public Class Methods

extended(base) click to toggle source
# File lib/paperclip/storage/aliyun.rb, line 4
def self.extended(base)
  base.instance_eval do
    @aliyun_options = @options[:aliyun]
  end

  [
    :aliyun_upload_url,   :aliyun_internal_url,
    :aliyun_external_url, :aliyun_alias_url
  ].each do |url_style|
    Paperclip.interpolates(url_style) do |attachment, style|
      attachment.send(url_style, style)
    end unless Paperclip::Interpolations.respond_to? url_style
  end
end

Public Instance Methods

aliyun_alias_url(style = default_style) click to toggle source
# File lib/paperclip/storage/aliyun.rb, line 39
def aliyun_alias_url(style = default_style)
  build_aliyun_object_url(oss_connection.aliyun_alias_host, style)
end
aliyun_external_url(style = default_style) click to toggle source
# File lib/paperclip/storage/aliyun.rb, line 35
def aliyun_external_url(style = default_style)
  build_aliyun_object_url(oss_connection.aliyun_external_host, style)
end
aliyun_internal_url(style = default_style) click to toggle source
# File lib/paperclip/storage/aliyun.rb, line 31
def aliyun_internal_url(style = default_style)
  build_aliyun_object_url(oss_connection.aliyun_internal_host, style)
end
aliyun_upload_url(style = default_style) click to toggle source
# File lib/paperclip/storage/aliyun.rb, line 27
def aliyun_upload_url(style = default_style)
  build_aliyun_object_url(oss_connection.aliyun_upload_host, style)
end
build_aliyun_object_url(host, style) click to toggle source
# File lib/paperclip/storage/aliyun.rb, line 19
def build_aliyun_object_url(host, style)
  if oss_connection.aliyun_protocol_relative_url
    "//#{host}/#{path(style).sub(%r{\A/}, '')}"
  else
    "#{oss_connection.aliyun_protocol}://#{host}/#{path(style).sub(%r{\A/}, '')}"
  end
end
copy_to_local_file(style, local_dest_path) click to toggle source
# File lib/paperclip/storage/aliyun.rb, line 65
def copy_to_local_file(style, local_dest_path)
  log("copying #{path(style)} to local file #{local_dest_path}")
  local_file = ::File.open(local_dest_path, 'wb')
  remote_file_str = oss_connection.get path(style)
  local_file.write(remote_file_str)
  local_file.close
end
exists?(style = default_style) click to toggle source
# File lib/paperclip/storage/aliyun.rb, line 43
def exists?(style = default_style)
  path(style) ? oss_connection.exists?(path(style)) : false
end
oss_connection() click to toggle source
# File lib/paperclip/storage/aliyun.rb, line 73
def oss_connection
  @oss_connection ||= ::Aliyun::Connection.new(
    Paperclip::Attachment.default_options[:aliyun].merge(@aliyun_options)
  )
end