Class: GcloudStorage::LocalStore

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud_storage/local_store.rb

Instance Method Summary collapse

Constructor Details

#initializeLocalStore

Returns a new instance of LocalStore.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gcloud_storage/local_store.rb', line 5

def initialize
  @path = "#{FileUtils.pwd}/public/"

  FileUtils.mkdir_p(@path + "/uploads") unless Dir.exist?(@path)

  @file = Struct.new(:path, :md5) do
    def signed_url(_arg1=nil,_arg2=nil)
      path
    end

    def delete
      abs_path = "#{@path}#{path}"
      ret = FileUtils.rm(abs_path) if File.exist?(abs_path)
      abs_path == ret[0] if ret
    end
  end
end

Instance Method Details

#bucket(_bucket_name = nil) ⇒ Object



31
32
33
# File 'lib/gcloud_storage/local_store.rb', line 31

def bucket(_bucket_name=nil)
  self
end

#file(file_path) ⇒ Object



35
36
37
38
# File 'lib/gcloud_storage/local_store.rb', line 35

def file(file_path)
  abs_file_path = "#{@path}#{file_path}"
  @file.new(abs_file_path)
end

#serviceObject



23
24
25
# File 'lib/gcloud_storage/local_store.rb', line 23

def service
  self
end

#storageObject



27
28
29
# File 'lib/gcloud_storage/local_store.rb', line 27

def storage
  self
end

#upload_file(file_path, dest_path) ⇒ Object



40
41
42
43
44
# File 'lib/gcloud_storage/local_store.rb', line 40

def upload_file file_path, dest_path
  dest_file_path = "#{@path}#{dest_path}"
  copy_file(file_path, dest_file_path)
  @file.new(dest_file_path, file_md5(dest_file_path))
end