Class: RakeRemoteFile::Task

Inherits:
Rake::FileTask
  • Object
show all
Defined in:
lib/rake-remote-file/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_fileObject

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_nameObject



33
34
35
# File 'lib/rake-remote-file/task.rb', line 33

def bucket_name
  name[%r{s3\.amazonaws\.com/(.*?)/(.*)}, 1]
end

#content_hashObject



25
26
27
# File 'lib/rake-remote-file/task.rb', line 25

def content_hash
  s3_object.etag
end

#extnameObject



41
42
43
# File 'lib/rake-remote-file/task.rb', line 41

def extname
  File.extname(source_file)
end

#mime_typeObject



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

Returns:

  • (Boolean)


13
14
15
# File 'lib/rake-remote-file/task.rb', line 13

def needed?
  @application.options.build_all || out_of_date?(timestamp)
end

#remote_pathObject



37
38
39
# File 'lib/rake-remote-file/task.rb', line 37

def remote_path
  name[%r{s3\.amazonaws\.com/(.*?)/(.*)}, 2]
end

#s3_objectObject



29
30
31
# File 'lib/rake-remote-file/task.rb', line 29

def s3_object
  @s3.bucket(bucket_name).object(remote_path)
end

#timestampObject



17
18
19
20
21
22
23
# File 'lib/rake-remote-file/task.rb', line 17

def timestamp
  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(options = {})
  options[:content_type] ||= mime_type

  s3_object.upload_file(source_file, options)
end