class MovieMasher::Transfer

Base class for Callback and Source as well as used directly to resolveInput and Output relative paths to a specific location.

There are three basic types of transfers - Type::FILE, Type::HTTP andType::S3 representing locations on the local drive, remote web servers andAWS S3 buckets respectively. Type::FILE transfers can either move, copy orcreate symbolic links for files. Type::HTTP (and Type::HTTPS) transfers cansupply authenticating parameters and Type::S3 transfers will use accesskeys 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 haveslashes inserted between them as needed so trailing and leading slashes areoptional.

Public Class Methods

create(hash = nil) click to toggle source

Returns a new instance.

# File lib/transfer.rb, line 19
def self.create(hash = nil)
  # puts "Transfer.create #{hash}"
  (hash.is_a?(Transfer) ? hash : Transfer.new(hash))
end
create_if(hash) click to toggle source
# File lib/transfer.rb, line 23
def self.create_if(hash)
  (hash ? create(hash) : nil)
end
file(mode, path, out_file) click to toggle source
# File lib/transfer.rb, line 26
def self.file(mode, path, out_file)
  path = File.expand_path(path) unless path.start_with?('/')
  if 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
    unless File.exist?(out_file)
      raise(Error::JobUpload, "could not #{mode} #{path} to #{out_file}")
    end
  end
end
init_hash(hash) click to toggle source
# File lib/transfer.rb, line 43
def self.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
new(hash = nil) click to toggle source
Calls superclass method
# File lib/transfer.rb, line 103
def initialize(hash = nil)
  self.class.init_hash hash
  super
end
query_string(transfer, job) click to toggle source
# File lib/transfer.rb, line 163
def self.query_string(transfer, job)
  parameters = transfer[:parameters]
  if parameters && parameters.is_a?(Hash) && !parameters.empty?
    parameters = Marshal.load(Marshal.dump(parameters))
    scope_object = {
      job: job,
      transfer.class_symbol => transfer
    }
    Evaluate.object(parameters, scope_object)
    parameters = URI.encode_www_form(parameters)
  end
  parameters
end

Public Instance Methods

__unless_empty(could_be_empty, s) click to toggle source
# File lib/transfer.rb, line 233
def __unless_empty(could_be_empty, s)
  (could_be_empty.to_s.empty? ? '' : s)
end
bucket() click to toggle source
# File lib/transfer.rb, line 55
def bucket
  _get __method__
end
bucket=(value) click to toggle source
String

Name of AWS S3 bucket where file is stored.

Types

Just Type::S3.

# File lib/transfer.rb, line 60
def bucket=(value)
  _set __method__, value
end
directory() click to toggle source
# File lib/transfer.rb, line 63
def directory
  _get __method__
end
directory=(value) click to toggle source
String

Added to URL after directory, before name, slashed.

Default

Nil means do not add to URL.

Types

Type::HTTP and Type::HTTPS.

# File lib/transfer.rb, line 69
def directory=(value)
  _set __method__, value
end
directory_path() click to toggle source
# File lib/transfer.rb, line 72
def directory_path
  Path.concat(directory, path)
end
error?() click to toggle source
# File lib/transfer.rb, line 75
def error?
  nil
end
extension() click to toggle source
# File lib/transfer.rb, line 78
def extension
  _get __method__
end
extension=(value) click to toggle source
String

Appended to file path after name, with period inserted between.

# File lib/transfer.rb, line 82
def extension=(value)
  _set __method__, value
end
file_name() click to toggle source
# File lib/transfer.rb, line 85
def file_name
  fn = Path.strip_slashes name
  fn += '.' + extension if extension
  fn
end
full_path() click to toggle source
# File lib/transfer.rb, line 90
def full_path
  fp = Path.concat directory_path, file_name
  # puts "#{self.class.name}#full_path #{fp}"
  fp
end
host() click to toggle source
# File lib/transfer.rb, line 95
def host
  _get __method__
end
host=(value) click to toggle source
String

Remote server name or IP address where file is stored.

Types

Type::HTTP and Type::HTTPS.

# File lib/transfer.rb, line 100
def host=(value)
  _set __method__, value
end
method() click to toggle source
# File lib/transfer.rb, line 107
def method
  _get __method__
end
method=(value) click to toggle source
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 114
def method=(value)
  _set __method__, value
end
name() click to toggle source
# File lib/transfer.rb, line 117
def name
  _get __method__
end
name=(value) click to toggle source
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 122
def name=(value)
  _set __method__, value
end
parameters() click to toggle source
# File lib/transfer.rb, line 125
def parameters
  _get __method__
end
parameters=(value) click to toggle source
Hash

Query string parameters to send with request for file. The valuesare evaluated, with Job and Input in scope.

Default

Nil means no query string used.

Types

Type::HTTP and Type::HTTPS.

# File lib/transfer.rb, line 132
def parameters=(value)
  _set __method__, value
end
pass() click to toggle source
# File lib/transfer.rb, line 135
def pass
  _get __method__
end
pass=(value) click to toggle source
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 141
def pass=(value)
  _set __method__, value
end
path() click to toggle source
# File lib/transfer.rb, line 144
def path
  _get __method__
end
path=(value) click to toggle source
String

Added to URL after directory, before name, slashed.

Default

Nil means do not add to URL.

Types

Type::HTTP and Type::HTTPS.

# File lib/transfer.rb, line 150
def path=(value)
  _set __method__, value
end
port() click to toggle source
# File lib/transfer.rb, line 153
def port
  _get __method__
end
port=(value) click to toggle source
Integer

Port number to contact host on.

Constant

Method::COPY, Method::MOVE or Method::SYMLINK.

Default

Nil means standard port for type.

Types

Type::HTTP and Type::HTTPS.

# File lib/transfer.rb, line 160
def port=(value)
  _set __method__, value
end
region() click to toggle source
# File lib/transfer.rb, line 176
def region
  _get __method__
end
region=(value) click to toggle source
String

Global AWS geographical region code.

Default

Nil means us-east-1 standard region.

Types

Just Type::S3.

# File lib/transfer.rb, line 182
def region=(value)
  _set __method__, value
end
relative?() click to toggle source
# File lib/transfer.rb, line 185
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
type() click to toggle source
# File lib/transfer.rb, line 191
def type
  _get __method__
end
type=(value) click to toggle source
String

The kind of transfer.

Constant

Type::FILE, Type::HTTP, Type::HTTPS or Type::S3.

Default

Type::FILE

# File lib/transfer.rb, line 197
def type=(value)
  _set __method__, value
end
url() click to toggle source
# File lib/transfer.rb, line 200
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
user() click to toggle source
# File lib/transfer.rb, line 224
def user
  _get __method__
end
user=(value) click to toggle source
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 230
def user=(value)
  _set __method__, value
end