class S3Direct::File
Attributes
identifier[R]
model[R]
options[R]
pattern[R]
Public Class Methods
new(model, identifier, pattern, opts={})
click to toggle source
# File lib/s3direct/file.rb, line 12 def initialize(model, identifier, pattern, opts={}) @model = model @identifier = identifier @pattern = pattern @options = default_options.merge(opts) end
sanitize_filename(name)
click to toggle source
# File lib/s3direct/file.rb, line 6 def self.sanitize_filename(name) unless name.nil? name.strip end end
Public Instance Methods
exists?()
click to toggle source
# File lib/s3direct/file.rb, line 48 def exists? name.present? end
key()
click to toggle source
# File lib/s3direct/file.rb, line 44 def key ::File.join(s3_path, name) end
max_upload_size()
click to toggle source
# File lib/s3direct/file.rb, line 52 def max_upload_size max_method = "#{identifier}_max_upload_size" if model.respond_to?(max_method) model.public_send(max_method) end end
name()
click to toggle source
# File lib/s3direct/file.rb, line 20 def name @model.send "#{identifier}_file" end
s3_path()
click to toggle source
# File lib/s3direct/file.rb, line 24 def s3_path StringInterpolator.new(model, pattern).to_s end
upload_request(filename = name, opts = {})
click to toggle source
# File lib/s3direct/file.rb, line 36 def upload_request(filename = name, opts = {}) if filename.blank? raise "Can't create an upload request without a filename - " + "provide it as an argument or set #{identifier}_file on the model" end UploadRequest.new s3_path, self.class.sanitize_filename(filename), options.merge(opts) end
url()
click to toggle source
# File lib/s3direct/file.rb, line 28 def url if exists? ::File.join(config.bucket_url, key) else default_url end end
Private Instance Methods
config()
click to toggle source
# File lib/s3direct/file.rb, line 62 def config ::S3Direct.config end
default_options()
click to toggle source
# File lib/s3direct/file.rb, line 66 def default_options Hash.new.tap do |h| h[:max_upload_size] = max_upload_size if max_upload_size end end
default_url()
click to toggle source
# File lib/s3direct/file.rb, line 72 def default_url options[:default_url] end