class Ccs::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:
-
STDIN/STDOUT: a `-` sign is interpreted as these standard streams
-
The Occson server: strings beginning with `ccs://` or `http(s)://` are interpreted as such
-
local files: everything not matching the previous descriptions is assumed to be a path on the local system
Public Class Methods
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/ccs/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
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/ccs/commands/copy.rb, line 36 def call download? ? download : upload end
Private Instance Methods
# File lib/ccs/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
# File lib/ccs/commands/copy.rb, line 42 def download? @source.match?(%r{\A(ccs|https?):\/\/}) end
# File lib/ccs/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