Class: Omnizip::Commands::ArchiveCreateCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/commands/archive_create_command.rb

Overview

Command to create .7z archives from files and directories.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ArchiveCreateCommand

Initialize archive create command with options.

Parameters:

  • options (Hash) (defaults to: {})

    Command options from Thor



28
29
30
# File 'lib/omnizip/commands/archive_create_command.rb', line 28

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



23
24
25
# File 'lib/omnizip/commands/archive_create_command.rb', line 23

def options
  @options
end

Instance Method Details

#run(output_file, *inputs) ⇒ void

This method returns an undefined value.

Execute the archive create command.

Parameters:

  • output_file (String)

    Path to output archive

  • inputs (Array<String>)

    Paths to files/directories to archive



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/omnizip/commands/archive_create_command.rb', line 37

def run(output_file, *inputs)
  validate_inputs(output_file, inputs)

  # Apply profile settings if specified
  opts = options.dup
  if opts[:profile]
    first_file = find_first_file(inputs)
    opts = apply_profile(first_file, opts)
  end

  # Determine format from extension or --format option
  format = opts[:format] || detect_format(output_file)

  if format == "rar"
    create_rar_archive(output_file, inputs, opts)
  else
    create_7z_archive(output_file, inputs, opts)
  end
end