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

create(hash = nil) click to toggle source

Returns

Returns a new instance.

# File lib/transfer.rb, line 21
def 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 26
def create_if(hash)
  (hash ? create(hash) : nil)
end
file(mode, path, out_file) click to toggle source
# 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
init_hash(hash) click to toggle source
# 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
new(hash = nil) click to toggle source
Calls superclass method
# File lib/transfer.rb, line 121
def initialize(hash = nil)
  self.class.init_hash hash
  super
end
query_string(transfer, job) click to toggle source
# 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

__unless_empty(could_be_empty, string) click to toggle source
# File lib/transfer.rb, line 270
def __unless_empty(could_be_empty, string)
  (could_be_empty.to_s.empty? ? '' : string)
end
bucket() click to toggle source
# File lib/transfer.rb, line 62
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 68
def bucket=(value)
  _set __method__, value
end
directory() click to toggle source
# File lib/transfer.rb, line 72
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 79
def directory=(value)
  _set __method__, value
end
directory_path() click to toggle source
# File lib/transfer.rb, line 83
def directory_path
  Path.concat(directory, path)
end
error?() click to toggle source
# File lib/transfer.rb, line 87
def error?
  nil
end
extension() click to toggle source
# File lib/transfer.rb, line 91
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 96
def extension=(value)
  _set __method__, value
end
file_name() click to toggle source
# File lib/transfer.rb, line 100
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 106
def full_path
  Path.concat directory_path, file_name
  # puts "#{self.class.name}#full_path #{fp}"
end
host() click to toggle source
# File lib/transfer.rb, line 111
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 117
def host=(value)
  _set __method__, value
end
method() click to toggle source
# File lib/transfer.rb, line 126
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 134
def method=(value)
  _set __method__, value
end
name() click to toggle source
# File lib/transfer.rb, line 138
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 144
def name=(value)
  _set __method__, value
end
parameters() click to toggle source
# File lib/transfer.rb, line 148
def parameters
  _get __method__
end
parameters=(value) click to toggle source
Hash

Query string parameters to send with request for file. The values are 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 156
def parameters=(value)
  _set __method__, value
end
pass() click to toggle source
# File lib/transfer.rb, line 160
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 167
def pass=(value)
  _set __method__, value
end
path() click to toggle source
# File lib/transfer.rb, line 171
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 178
def path=(value)
  _set __method__, value
end
port() click to toggle source
# File lib/transfer.rb, line 182
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 190
def port=(value)
  _set __method__, value
end
region() click to toggle source
# File lib/transfer.rb, line 204
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 211
def region=(value)
  _set __method__, value
end
relative?() click to toggle source
# 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
type() click to toggle source
# File lib/transfer.rb, line 223
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 230
def type=(value)
  _set __method__, value
end
url() click to toggle source
# 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
user() click to toggle source
# File lib/transfer.rb, line 259
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 266
def user=(value)
  _set __method__, value
end