Class: Omnizip::Commands::MetadataCommand

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

Overview

Metadata command implementation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MetadataCommand

Returns a new instance of MetadataCommand.



9
10
11
# File 'lib/omnizip/commands/metadata_command.rb', line 9

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/omnizip/commands/metadata_command.rb', line 7

def options
  @options
end

Instance Method Details

#run(archive_path, pattern = nil) ⇒ Object

Run the metadata command

Parameters:

  • archive_path (String)

    Path to archive

  • pattern (String, nil) (defaults to: nil)

    Optional pattern to match entries



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/omnizip/commands/metadata_command.rb', line 16

def run(archive_path, pattern = nil)
  unless File.exist?(archive_path)
    raise Errno::ENOENT, "Archive not found: #{archive_path}"
  end

  Omnizip::Zip::File.open(archive_path) do |archive|
    if options[:show]
      (archive, pattern)
    else
      (archive, pattern)
    end
  end

  puts "Metadata updated successfully" unless options[:show]
end