Module: Zipr
- Defined in:
- lib/zipr/sfx.rb,
lib/zipr/config.rb,
lib/zipr/helper.rb,
lib/zipr/archive.rb
Defined Under Namespace
Class Method Summary collapse
- .checksums_folder ⇒ Object
- .config ⇒ Object
- .defaults ⇒ Object
-
.flattened_paths(source_folder, files) ⇒ Object
returns results of all files found in the array of files, including files found by wildcard, as relative paths.
- .prepend_source_folder(source_folder, entry) ⇒ Object
- .seven_zip_exe_from_registry ⇒ Object
- .seven_zip_executable_path ⇒ Object
- .slice_source_folder(source_folder, entry) ⇒ Object
- .wildcard_to_regexp(entry) ⇒ Object
Class Method Details
.checksums_folder ⇒ Object
59 60 61 |
# File 'lib/zipr/helper.rb', line 59 def checksums_folder "#{@cache_path}/zipr/archive_checksums" end |
.config ⇒ Object
4 5 6 |
# File 'lib/zipr/config.rb', line 4 def config @config ||= EasyJSON.config(defaults: defaults) end |
.defaults ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/zipr/config.rb', line 8 def defaults { 'paths' => { 'cache' => Dir.tmpdir, }, } end |
.flattened_paths(source_folder, files) ⇒ Object
returns results of all files found in the array of files, including files found by wildcard, as relative paths.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/zipr/helper.rb', line 21 def flattened_paths(source_folder, files) return files if source_folder.nil? || source_folder.empty? result = [] source_folder_glob = nil files.each do |entry| if entry.is_a?(Regexp) source_folder_glob ||= Dir.glob("#{source_folder.tr('\\', '/')}/**/*") matched_files = source_folder_glob.select { |path| path =~ entry } result += matched_files.map { |f| slice_source_folder(source_folder, f) } next end standardized_entry = "#{source_folder.tr('\\', '/')}/#{slice_source_folder(source_folder, entry)}" files_found = Dir.glob(standardized_entry) if files_found.empty? result.push(entry) else result += files_found.map { |f| slice_source_folder(source_folder, f) } end end result end |
.prepend_source_folder(source_folder, entry) ⇒ Object
50 51 52 53 |
# File 'lib/zipr/helper.rb', line 50 def prepend_source_folder(source_folder, entry) return entry.tr('\\', '/') if source_folder.nil? || source_folder.empty? || entry.tr('\\', '/').start_with?(source_folder.tr('\\', '/')) "#{source_folder.tr('\\', '/')}/#{entry.tr('\\', '/')}" end |
.seven_zip_exe_from_registry ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/zipr/helper.rb', line 12 def seven_zip_exe_from_registry key_path = 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe' return nil unless EasyIO::Registry.key_exists?(key_path) # Read path from recommended Windows App Paths registry location # docs: https://msdn.microsoft.com/en-us/library/windows/desktop/ee872121 EasyIO::Registry.read(key_path, 'Path') end |
.seven_zip_executable_path ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/zipr/helper.rb', line 4 def seven_zip_executable_path path = node['seven_zip']['home'] EasyIO.logger.debug "7-zip home: '#{path}'" unless path.nil? path ||= seven_zip_exe_from_registry if OS.windows? EasyIO.logger.debug "7-zip path: '#{path}'" ::File.join(path, OS.windows? ? '7z.exe' : '7z') end |
.slice_source_folder(source_folder, entry) ⇒ Object
55 56 57 |
# File 'lib/zipr/helper.rb', line 55 def slice_source_folder(source_folder, entry) entry.tr('\\', '/').sub(source_folder.tr('\\', '/'), '').reverse.chomp('/').reverse end |
.wildcard_to_regexp(entry) ⇒ Object
44 45 46 47 48 |
# File 'lib/zipr/helper.rb', line 44 def wildcard_to_regexp(entry) return entry if entry.is_a?(Regexp) escaped_entry = Regexp.escape(entry).gsub(/\\\*/, '.*') # Convert asterisks to .* /#{escaped_entry}/ end |