Class: ArtifactTools::Uploader

Inherits:
Object
  • Object
show all
Includes:
Hasher
Defined in:
lib/artifact_tools/uploader.rb

Overview

Uploader allows the user to upload files to a store specified by ConfigFile.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hasher

#file_hash

Constructor Details

#initialize(config_file:, files:, append: false) ⇒ Uploader

Upload requested files

Parameters:

  • config_file (String)

    Path to configuration file

  • append (Boolean) (defaults to: false)

    Whether to append files to config file

  • files (Array(String))

    Paths to files to upload



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/artifact_tools/uploader.rb', line 18

def initialize(config_file:, files:, append: false)
  # TODO: check for clashes of files, do hash checks?
  @config_file = config_file
  @append = append
  @config = load_config(@config_file)
  c = ArtifactTools::Client.new(config: @config.config)
  files.each do |file|
    update_file(c, file)
  end
  @config.save(config_file)
end

Class Method Details

.parse(arguments) ⇒ Object

Parse command line options to options suitable to Downloader.new

Parameters:

  • arguments (Array(String))

    Command line options to parse and use. Hint: pass ARGV

Raises:

  • (OptionParser::MissingArgument)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/artifact_tools/uploader.rb', line 48

def self.parse(arguments)
  options = { append: @default_append_opt }
  arguments << '-h' if arguments.empty?
  OptionParser.new do |opts|
    opts.banner = "Usage: #{__FILE__} [options]"
    @parse_opts_handlers.each do |args, handler|
      opts.on(*args) { |v|  handler.call(opts, v, options) }
    end
  end.parse!(arguments)

  raise OptionParser::MissingArgument, 'Missing -c/--configuration option' unless options.key?(:config_file)

  options.merge({ files: arguments.dup })
end