class MovieMasher::Transfer
Base class for Callback
and Source
as well as used directly to resolve Input
and Output
relative paths to a specific location.
There are three basic types of transfers - Type::FILE, Type::HTTP and Type::S3 representing locations on the local drive, remote web servers and AWS S3 buckets respectively. Type::FILE transfers can either move, copy or create symbolic links for files. Type::HTTP (and Type::HTTPS) transfers can supply authenticating parameters
and Type::S3 transfers will use access keys provided in the configuration or any mechanism supported by aws-sdk (environmental variables, instance roles, etc.).
When building file paths, directory
and path
will automatically have slashes inserted between them as needed so trailing and leading slashes are optional.
Public Class Methods
# File lib/transfer.rb, line 26 def create_if(hash) (hash ? create(hash) : nil) end
# File lib/transfer.rb, line 30 def file(mode, path, out_file) path = File.expand_path(path) unless path.start_with?('/') return unless File.exist?(path) out_file = File.expand_path(out_file) unless out_file.start_with?('/') case mode when Method::COPY FileUtils.copy(path, out_file) when Method::MOVE FileUtils.move(path, out_file) else # Method::SYMLINK FileUtils.symlink(path, out_file) end return if File.exist?(out_file) raise(Error::JobUpload, "could not #{mode} #{path} to #{out_file}") end
# File lib/transfer.rb, line 48 def init_hash(hash) Hashable._init_key hash, :type, Type::FILE case hash[:type] when Type::S3 Hashable._init_key(hash, :acl, 'public-read') when Type::FILE Hashable._init_key(hash, :method, Method::MOVE) when Type::HTTP Hashable._init_key(hash, :method, Method::POST) end hash end
# File lib/transfer.rb, line 121 def initialize(hash = nil) self.class.init_hash hash super end
# File lib/transfer.rb, line 194 def self.query_string(transfer, job) parameters = transfer[:parameters] if parameters.is_a?(Hash) && !parameters.empty? parameters = Marshal.load(Marshal.dump(parameters)) Evaluate.object(parameters, job: job, transfer: transfer) parameters = URI.encode_www_form(parameters) end parameters end
Public Instance Methods
# File lib/transfer.rb, line 270 def __unless_empty(could_be_empty, string) (could_be_empty.to_s.empty? ? '' : string) end
# File lib/transfer.rb, line 62 def bucket _get __method__ end
- String
-
Name of AWS S3 bucket where file is stored.
- Types
-
Just Type::S3.
# File lib/transfer.rb, line 68 def bucket=(value) _set __method__, value end
# File lib/transfer.rb, line 72 def directory _get __method__ end
# File lib/transfer.rb, line 83 def directory_path Path.concat(directory, path) end
# File lib/transfer.rb, line 87 def error? nil end
# File lib/transfer.rb, line 91 def extension _get __method__ end
- String
-
Appended to file path after
name
, with period inserted between.
# File lib/transfer.rb, line 96 def extension=(value) _set __method__, value end
# File lib/transfer.rb, line 100 def file_name fn = Path.strip_slashes name fn += ".#{extension}" if extension fn end
# File lib/transfer.rb, line 106 def full_path Path.concat directory_path, file_name # puts "#{self.class.name}#full_path #{fp}" end
# File lib/transfer.rb, line 111 def host _get __method__ end
- String
-
Remote server name or IP address where file is stored.
- Types
-
Type::HTTP and Type::HTTPS.
# File lib/transfer.rb, line 117 def host=(value) _set __method__, value end
# File lib/transfer.rb, line 126 def method _get __method__ end
- String
-
How to retrieve the file.
- Constant
-
Method::COPY, Method::MOVE or Method::SYMLINK.
- Default
-
Method::SYMLINK
- Types
-
Just Type::FILE.
# File lib/transfer.rb, line 134 def method=(value) _set __method__, value end
# File lib/transfer.rb, line 138 def name _get __method__ end
- String
-
The full or basename of file appended to file path. If full,
extension
will be set and removed from value.
# File lib/transfer.rb, line 144 def name=(value) _set __method__, value end
# File lib/transfer.rb, line 148 def parameters _get __method__ end
# File lib/transfer.rb, line 160 def pass _get __method__ end
- String
-
Password for standard HTTP authentication.
- Default
-
Nil means do not provide authenticating details.
- Types
-
Type::HTTP and Type::HTTPS.
# File lib/transfer.rb, line 167 def pass=(value) _set __method__, value end
# File lib/transfer.rb, line 171 def path _get __method__ end
# File lib/transfer.rb, line 182 def port _get __method__ end
# File lib/transfer.rb, line 204 def region _get __method__ end
- String
-
Global AWS geographical region code.
- Default
-
Nil means us-east-1 standard region.
- Types
-
Just Type::S3.
# File lib/transfer.rb, line 211 def region=(value) _set __method__, value end
# File lib/transfer.rb, line 215 def relative? return false if Type::S3 == type return false if host && !host.empty? is_file = (Type::FILE == type) !(is_file && full_path.start_with?('/') && File.exist?(full_path)) end
# File lib/transfer.rb, line 223 def type _get __method__ end
- String
-
The kind of transfer.
- Constant
-
Type::FILE, Type::HTTP, Type::HTTPS or Type::S3.
- Default
-
Type::FILE
# File lib/transfer.rb, line 230 def type=(value) _set __method__, value end
# File lib/transfer.rb, line 234 def url u = @hash[:url] unless u u = '' case type when Type::HTTP, Type::HTTPS unless host.to_s.empty? u += "#{type}://#{host}" u += __unless_empty(port, ":#{port}") end u = Path.concat(u, full_path) when Type::S3 u += __unless_empty(bucket, "#{bucket}.") u += 's3' u += __unless_empty(region, "-#{region}") u += '.amazonaws.com' u = Path.concat(u, full_path) when Type::FILE u = full_path end end # puts "#{self.class.name}#url #{u}" u end
# File lib/transfer.rb, line 259 def user _get __method__ end
- String
-
Username for standard HTTP authentication.
- Default
-
Nil means do not provide authenticating details.
- Types
-
Type::HTTP and Type::HTTPS.
# File lib/transfer.rb, line 266 def user=(value) _set __method__, value end