Class: S3FileField::S3Uploader
- Inherits:
-
Object
- Object
- S3FileField::S3Uploader
- Defined in:
- lib/s3_file_field/s3_uploader.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #field_data_options ⇒ Object
- #field_options ⇒ Object
-
#initialize(original_options = {}) ⇒ S3Uploader
constructor
A new instance of S3Uploader.
Constructor Details
#initialize(original_options = {}) ⇒ S3Uploader
Returns a new instance of S3Uploader.
5 6 7 8 9 10 11 12 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 |
# File 'lib/s3_file_field/s3_uploader.rb', line 5 def initialize( = {}) = { access_key_id: S3FileField.config.access_key_id, secret_access_key: S3FileField.config.secret_access_key, bucket: S3FileField.config.bucket, acl: "public-read", expiration: 10.hours.from_now.utc.iso8601, max_file_size: 500.megabytes, conditions: [], key_starts_with: S3FileField.config.key_starts_with || 'uploads/', region: S3FileField.config.region || 's3', url: S3FileField.config.url, ssl: S3FileField.config.ssl } @key = [:key] @original_options = # Remove s3_file_field specific options from original options = @original_options.extract!(*.keys). reject { |k, v| v.nil? } @options = .merge() unless @options[:access_key_id] raise Error.new("Please configure access_key_id option.") end unless @options[:secret_access_key] raise Error.new("Please configure secret_access_key option.") end if @options[:bucket].nil? && @options[:url].nil? raise Error.new("Please configure bucket name or url.") end end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/s3_file_field/s3_uploader.rb', line 3 def @options end |
Instance Method Details
#field_data_options ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/s3_file_field/s3_uploader.rb', line 47 def { url: url, key: key, acl: @options[:acl], aws_access_key_id: @options[:access_key_id], policy: policy, signature: signature }.merge(@original_options[:data] || {}) end |
#field_options ⇒ Object
43 44 45 |
# File 'lib/s3_file_field/s3_uploader.rb', line 43 def @original_options.merge(data: ) end |