Class: Balloon::Storage::Store
- Inherits:
-
Object
- Object
- Balloon::Storage::Store
- Defined in:
- lib/balloon/storage/store.rb
Class Method Summary collapse
- .basic_auth(&block) ⇒ Object
- .conn_option(&block) ⇒ Object
- .get_basic_auth(klass) ⇒ Object
- .get_option(klass) ⇒ Object
- .token_auth(&block) ⇒ Object
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(uploader) ⇒ Store
constructor
A new instance of Store.
- #retrieve!(size_name = nil) ⇒ Object
- #set_upload_name(size_name = nil) ⇒ Object
- #store! ⇒ Object
- #store_name ⇒ Object
- #upload_dir ⇒ Object
- #upload_file ⇒ Object
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
#connection ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/balloon/storage/store.rb', line 52 def connection = self.class.get_option(self) basic = self.class.get_basic_auth(self) token = self.class.token_auth conn = Http::Client.new([:url]) do |builder| builder.headers = [: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 ) = @uploader. if size_name return store_name + "_#{size_name.to_s}" + "." + [:extension] end store_name + "." + [:extension] end |
#store! ⇒ Object
8 |
# File 'lib/balloon/storage/store.rb', line 8 def store!; end |
#store_name ⇒ Object
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.[: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_dir ⇒ Object
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_file ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/balloon/storage/store.rb', line 12 def upload_file file_info = @uploader. return {} if file_info.nil? basename = file_info[:basename] || "" extension = file_info[:extension] || "" { basename: basename, extension: extension } end |