Class: RakeRemoteFile::Task
- Inherits:
-
Rake::FileTask
- Object
- Rake::FileTask
- RakeRemoteFile::Task
- Defined in:
- lib/rake-remote-file/task.rb
Instance Attribute Summary collapse
-
#source_file ⇒ Object
Returns the value of attribute source_file.
Instance Method Summary collapse
- #bucket_name ⇒ Object
- #content_hash ⇒ Object
- #extname ⇒ Object
-
#initialize(task_name, app) ⇒ Task
constructor
A new instance of Task.
- #mime_type ⇒ Object
- #needed? ⇒ Boolean
- #remote_path ⇒ Object
- #s3_object ⇒ Object
- #timestamp ⇒ Object
- #upload(options = {}) ⇒ Object
Constructor Details
#initialize(task_name, app) ⇒ Task
Returns a new instance of Task.
8 9 10 11 |
# File 'lib/rake-remote-file/task.rb', line 8 def initialize(task_name, app) @s3 = Aws::S3::Resource.new super(task_name, app) end |
Instance Attribute Details
#source_file ⇒ Object
Returns the value of attribute source_file.
6 7 8 |
# File 'lib/rake-remote-file/task.rb', line 6 def source_file @source_file end |
Instance Method Details
#bucket_name ⇒ Object
33 34 35 |
# File 'lib/rake-remote-file/task.rb', line 33 def bucket_name name[%r{s3\.amazonaws\.com/(.*?)/(.*)}, 1] end |
#content_hash ⇒ Object
25 26 27 |
# File 'lib/rake-remote-file/task.rb', line 25 def content_hash s3_object.etag end |
#extname ⇒ Object
41 42 43 |
# File 'lib/rake-remote-file/task.rb', line 41 def extname File.extname(source_file) end |
#mime_type ⇒ Object
45 46 47 48 |
# File 'lib/rake-remote-file/task.rb', line 45 def mime_type ext = extname.strip.downcase[1..-1] MIME::Types.type_for(ext).first.to_s end |
#needed? ⇒ Boolean
13 14 15 |
# File 'lib/rake-remote-file/task.rb', line 13 def needed? @application..build_all || out_of_date?() end |
#remote_path ⇒ Object
37 38 39 |
# File 'lib/rake-remote-file/task.rb', line 37 def remote_path name[%r{s3\.amazonaws\.com/(.*?)/(.*)}, 2] end |
#s3_object ⇒ Object
29 30 31 |
# File 'lib/rake-remote-file/task.rb', line 29 def s3_object @s3.bucket(bucket_name).object(remote_path) end |
#timestamp ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/rake-remote-file/task.rb', line 17 def s3_object.last_modified rescue StandardError # if we cannot read last_modified, assume the file # is extremely old Rake::EARLY end |
#upload(options = {}) ⇒ Object
50 51 52 53 54 |
# File 'lib/rake-remote-file/task.rb', line 50 def upload( = {}) [:content_type] ||= mime_type s3_object.upload_file(source_file, ) end |