Class: SafeZip::ExtractParams
- Inherits:
-
Object
- Object
- SafeZip::ExtractParams
- Includes:
- Gitlab::Utils::StrongMemoize
- Defined in:
- lib/safe_zip/extract_params.rb
Instance Attribute Summary collapse
-
#directories ⇒ Object
readonly
Returns the value of attribute directories.
-
#extract_path ⇒ Object
readonly
Returns the value of attribute extract_path.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Instance Method Summary collapse
- #directories_wildcard ⇒ Object
-
#initialize(to:, directories: [], files: []) ⇒ ExtractParams
constructor
A new instance of ExtractParams.
- #matching_target_directory(path) ⇒ Object
- #matching_target_file(path) ⇒ Object
- #target_directories ⇒ Object
Constructor Details
#initialize(to:, directories: [], files: []) ⇒ ExtractParams
Returns a new instance of ExtractParams.
9 10 11 12 13 14 |
# File 'lib/safe_zip/extract_params.rb', line 9 def initialize(to:, directories: [], files: []) @directories = directories @files = files @extract_path = ::File.realpath(to) validate! end |
Instance Attribute Details
#directories ⇒ Object (readonly)
Returns the value of attribute directories.
7 8 9 |
# File 'lib/safe_zip/extract_params.rb', line 7 def directories @directories end |
#extract_path ⇒ Object (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 |
#files ⇒ Object (readonly)
Returns the value of attribute files.
7 8 9 |
# File 'lib/safe_zip/extract_params.rb', line 7 def files @files end |
Instance Method Details
#directories_wildcard ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/safe_zip/extract_params.rb', line 30 def directories_wildcard strong_memoize(:directories_wildcard) do directories.map do |directory| ::File.join(directory, '*') end end end |
#matching_target_directory(path) ⇒ Object
16 17 18 19 20 |
# File 'lib/safe_zip/extract_params.rb', line 16 def matching_target_directory(path) target_directories.find do |directory| path.start_with?(directory) end end |
#matching_target_file(path) ⇒ Object
38 39 40 |
# File 'lib/safe_zip/extract_params.rb', line 38 def matching_target_file(path) target_files.include?(path) end |
#target_directories ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/safe_zip/extract_params.rb', line 22 def target_directories strong_memoize(:target_directories) do directories.map do |directory| ::File.join(::File.(directory, extract_path), '') end end end |