class CarrierWave::Storage::Yandex::Disk

Rubocop, shut up

Public Instance Methods

helper_create_publish(file) click to toggle source

Store a single file

# File lib/carrierwave/yandex/storage/disk.rb, line 12
def helper_create_publish(file)
  location = "/#{uploader.store_path}"
  location_path = "/#{uploader.store_dir}"

  yandex_disk_client.mkdir_p(location_path)

  yandex_disk_client.put!(file.path.to_s, location)

  yandex_disk_client.make_public(location)
end
helper_update_model(make_public_res) click to toggle source
# File lib/carrierwave/yandex/storage/disk.rb, line 23
def helper_update_model(make_public_res)
  location = "/#{uploader.store_path}"

  public_url = ERB::Util.url_encode make_public_res[:public_url]

  file_id = { location: location, public_url: public_url }.to_json

  uploader.model.update_column uploader.mounted_as, file_id
end
retrieve!(file_id) click to toggle source

Retrieve a single file

# File lib/carrierwave/yandex/storage/disk.rb, line 42
def retrieve!(file_id)
  file_id_hash = (JSON.parse file_id.gsub('=>', ':')).symbolize_keys

  public_url = file_id_hash[:public_url]

  location = file_id_hash[:location]

  CarrierWave::Storage::Yandex::Disk::File
    .new(public_url, location, yandex_disk_client)
end
store!(file) click to toggle source
# File lib/carrierwave/yandex/storage/disk.rb, line 33
def store!(file)
  # I had to break this method into 2 helpers just because
  # rubocop insisted on that. Isn't it stupid?
  res = helper_create_publish(file)

  helper_update_model(res)
end
yandex_disk_client() click to toggle source
# File lib/carrierwave/yandex/storage/disk.rb, line 53
def yandex_disk_client
  @yandex_disk_client ||= begin
    ::Yandex::Disk::Client.new(access_token: config[:access_token])
  end
end

Private Instance Methods

config() click to toggle source
# File lib/carrierwave/yandex/storage/disk.rb, line 61
def config
  @config ||= {}

  @config[:access_token] ||= uploader.yandex_disk_access_token

  @config
end