Class: Balloon::Storage::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/balloon/storage/store.rb

Direct Known Subclasses

File, Upyun

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uploader) ⇒ Store

Returns a new instance of Store.



4
5
6
# File 'lib/balloon/storage/store.rb', line 4

def initialize(uploader)
  @uploader = uploader
end

Class Method Details

.basic_auth(&block) ⇒ Object



74
75
76
77
# File 'lib/balloon/storage/store.rb', line 74

def basic_auth(&block)
  return @basic_proc unless block_given?
  @basic_proc = block
end

.conn_option(&block) ⇒ Object



65
66
67
68
# File 'lib/balloon/storage/store.rb', line 65

def conn_option(&block)
  return @option_proc unless block_given?
  @option_proc = block
end

.get_basic_auth(klass) ⇒ Object



79
80
81
82
# File 'lib/balloon/storage/store.rb', line 79

def get_basic_auth(klass)
  return nil if basic_auth.nil?
  klass.instance_eval(&basic_auth)
end

.get_option(klass) ⇒ Object



70
71
72
# File 'lib/balloon/storage/store.rb', line 70

def get_option(klass)
  klass.instance_eval(&conn_option)
end

.token_auth(&block) ⇒ Object



84
85
86
87
# File 'lib/balloon/storage/store.rb', line 84

def token_auth(&block)
  return @token_proc unless block_given?
  @token_proc = block
end

Instance Method Details

#connectionObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/balloon/storage/store.rb', line 52

def connection
  options = self.class.get_option(self)
  basic = self.class.get_basic_auth(self)
  token = self.class.token_auth
  conn = Http::Client.new(options[:url]) do |builder|
    builder.headers = options[:headers]
    builder.basic_auth(basic[:user], basic[:password]) if !basic.nil?
    builder.token_auth(self, token) if !token.nil?
  end
  return conn
end

#retrieve!(size_name = nil) ⇒ Object



10
# File 'lib/balloon/storage/store.rb', line 10

def retrieve!(size_name = nil); end

#set_upload_name(size_name = nil) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/balloon/storage/store.rb', line 44

def set_upload_name(size_name = nil )
  cache_meta = @uploader.cache_meta
  if size_name
    return store_name + "_#{size_name.to_s}" + "." + cache_meta[:extension]
  end
  store_name + "." + cache_meta[:extension]
end

#store!Object



8
# File 'lib/balloon/storage/store.rb', line 8

def store!; end

#store_nameObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/balloon/storage/store.rb', line 25

def store_name
  if !@uploader.respond_to?(:uploader_name_format)
    return @uploader.cache_meta[:basename]
  end

  name_format = @uploader.uploader_name_format
  name = name_format[:name]

  if name_format[:format].to_s == "downcase"
    return name.downcase
  end

  if name_format[:format].to_s == "upcase"
    return name.upcase
  end

  name
end

#upload_dirObject



21
22
23
# File 'lib/balloon/storage/store.rb', line 21

def upload_dir
  @uploader.respond_to?(:uploader_dir) ? @uploader.uploader_dir : @uploader.uploader_name
end

#upload_fileObject



12
13
14
15
16
17
18
19
# File 'lib/balloon/storage/store.rb', line 12

def upload_file
  file_info = @uploader.meta
  return {} if file_info.nil?

  basename = file_info[:basename] || ""
  extension = file_info[:extension] || ""
  { basename: basename, extension: extension }
end