Class: SafeZip::ExtractParams

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
lib/safe_zip/extract_params.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(directories:, to:) ⇒ ExtractParams

Returns a new instance of ExtractParams.


9
10
11
12
# File 'lib/safe_zip/extract_params.rb', line 9

def initialize(directories:, to:)
  @directories = directories
  @extract_path = ::File.realpath(to)
end

Instance Attribute Details

#directoriesObject (readonly)

Returns the value of attribute directories


7
8
9
# File 'lib/safe_zip/extract_params.rb', line 7

def directories
  @directories
end

#extract_pathObject (readonly)

Returns the value of attribute extract_path


7
8
9
# File 'lib/safe_zip/extract_params.rb', line 7

def extract_path
  @extract_path
end

Instance Method Details

#directories_wildcardObject


28
29
30
31
32
33
34
# File 'lib/safe_zip/extract_params.rb', line 28

def directories_wildcard
  strong_memoize(:directories_wildcard) do
    directories.map do |directory|
      ::File.join(directory, '*')
    end
  end
end

#matching_target_directory(path) ⇒ Object


14
15
16
17
18
# File 'lib/safe_zip/extract_params.rb', line 14

def matching_target_directory(path)
  target_directories.find do |directory|
    path.start_with?(directory)
  end
end

#target_directoriesObject


20
21
22
23
24
25
26
# File 'lib/safe_zip/extract_params.rb', line 20

def target_directories
  strong_memoize(:target_directories) do
    directories.map do |directory|
      ::File.join(::File.expand_path(directory, extract_path), '')
    end
  end
end