Class: SourceFile
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SourceFile
- Defined in:
- lib/generators/s3_cors_fileupload/install/templates/source_file.rb
Class Method Summary collapse
Instance Method Summary collapse
- #is_image? ⇒ Boolean
-
#s3_object ⇒ Object
—- start S3 related methods —–.
- #to_jq_upload ⇒ Object
Class Method Details
.open_aws ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/generators/s3_cors_fileupload/install/templates/source_file.rb', line 42 def self.open_aws unless AWS::S3::Base.connected? AWS::S3::Base.establish_connection!( :access_key_id => S3CorsFileupload::Config.access_key_id, :secret_access_key => S3CorsFileupload::Config.secret_access_key ) end return AWS::S3::Base.connected? end |
Instance Method Details
#is_image? ⇒ Boolean
31 32 33 |
# File 'lib/generators/s3_cors_fileupload/install/templates/source_file.rb', line 31 def is_image? !!file_content_type.try(:match, /image/) end |
#s3_object ⇒ Object
—- start S3 related methods —–
36 37 38 39 40 |
# File 'lib/generators/s3_cors_fileupload/install/templates/source_file.rb', line 36 def s3_object @s3_object ||= AWS::S3::S3Object.find(key, bucket) if self.class.open_aws && key rescue nil end |
#to_jq_upload ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/generators/s3_cors_fileupload/install/templates/source_file.rb', line 20 def to_jq_upload { 'id' => id, 'name' => file_name, 'size' => file_size, 'url' => url, 'image' => self.is_image?, 'delete_url' => Rails.application.routes.url_helpers.source_file_path(self) } end |