class Occson::Commands::Copy

The copy command, responsible for copying a target to a destination, performing encryption and decryption as necessary.

The target and destinations can be:

Public Class Methods

new(source, destination, access_token, passphrase, force: false) click to toggle source

Builds an instance of the Copy command.

@param source [String] ‘-` for STDIN, an URI or a local file path @param destination [String] `-` for STDOUT, an URI or a local file path @param access_token [String] Occson access token @param passphrase [String] Passphrase used for encryption of the document @param force [Boolean] Whether to overwrite target document in Occson, if any. Default `false`.

# File lib/occson/commands/copy.rb, line 24
def initialize(source, destination, access_token, passphrase, force: false)
  @source = source
  @destination = destination
  @access_token = access_token
  @passphrase = passphrase
  @force = force
end

Public Instance Methods

call() click to toggle source

Performs a transfer between locations - an upload if ‘@source` is local or STDIN, a download if `@source` is an URI.

No guarantees are made about the return values of this method.

# File lib/occson/commands/copy.rb, line 36
def call
  download? ? download : upload
end

Private Instance Methods

download() click to toggle source
# File lib/occson/commands/copy.rb, line 46
def download
  content = Document.new(@source, @access_token, @passphrase).download
  return unless content

  (@destination.eql?('-') ? STDOUT : File.new(@destination, 'w')).print content
end
download?() click to toggle source
# File lib/occson/commands/copy.rb, line 42
def download?
  @source.match?(%r{\A(occson|https?):\/\/})
end
upload() click to toggle source
# File lib/occson/commands/copy.rb, line 53
def upload
  content = @source.eql?('-') ? STDIN.read : File.read(@source)
  Document.new(@destination, @access_token, @passphrase).upload(content, force: @force)
end