Class: CarrierWave::Storage::Box

Inherits:
Abstract
  • Object
show all
Defined in:
lib/carrierwave/storage/box.rb

Defined Under Namespace

Classes: File

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#client_boxObject (readonly)

Stubs we must implement to create and save



11
12
13
# File 'lib/carrierwave/storage/box.rb', line 11

def client_box
  @client_box
end

Instance Method Details

#retrieve!(file) ⇒ Object

Retrieve a single file



55
56
57
58
# File 'lib/carrierwave/storage/box.rb', line 55

def retrieve!(file)
  @client_box = box_client
  CarrierWave::Storage::Box::File.new(uploader, config, uploader.store_path(file), @client_box)
end

#store!(file) ⇒ Object

Store a single file



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/carrierwave/storage/box.rb', line 13

def store!(file)
  @client_box = box_client
  # if @client_box
  path_folders = uploader.store_dir.split('/')
  begin
    path_temp = path_folders[0...-1].join('/')

    folder_will_up = @client_box.folder_from_path(path_temp)
    begin
      @client_box.create_folder(path_folders.last, folder_will_up)
    rescue Boxr::BoxrError => e
    end
    folder_will_up = @client_box.folder_from_path(uploader.store_dir)
    file_up = @client_box.upload_file(file.to_file, folder_will_up)
    file
  rescue  Boxr::BoxrError => e

    path_folders.each_with_index do |path, index|
      if index==0
        begin
          @client_box.create_folder("#{path}", "#{Boxr::ROOT}")
        rescue Boxr::BoxrError => e
          next
        end
      else
        begin
          parent = @client_box.folder_from_path("#{path_folders[0..index-1].join('/')}")
          @client_box.create_folder("#{path}", parent)
        rescue Boxr::BoxrError => e
          next
        end
      end
    end

    folder_will_up = @client_box.folder_from_path(uploader.store_dir)
    file_up = @client_box.upload_file(file.to_file, uploader.store_dir)
  end

  file
end