Module: UnpackStrategy
- Extended by:
- T::Helpers, T::Sig
- Includes:
- SystemCommand::Mixin
- Included in:
- Air, Bzip2, Cab, Directory, Dmg, Fossil, GenericUnar, Gzip, Lha, Lzip, Lzma, P7Zip, Pax, Rar, Tar, Uncompressed, Xar, Xz, Zip
- Defined in:
- Library/Homebrew/unpack_strategy.rb,
Library/Homebrew/unpack_strategy/xz.rb,
Library/Homebrew/unpack_strategy/air.rb,
Library/Homebrew/unpack_strategy/cab.rb,
Library/Homebrew/unpack_strategy/cvs.rb,
Library/Homebrew/unpack_strategy/dmg.rb,
Library/Homebrew/unpack_strategy/git.rb,
Library/Homebrew/unpack_strategy/jar.rb,
Library/Homebrew/unpack_strategy/lha.rb,
Library/Homebrew/unpack_strategy/otf.rb,
Library/Homebrew/unpack_strategy/pax.rb,
Library/Homebrew/unpack_strategy/pkg.rb,
Library/Homebrew/unpack_strategy/rar.rb,
Library/Homebrew/unpack_strategy/sit.rb,
Library/Homebrew/unpack_strategy/tar.rb,
Library/Homebrew/unpack_strategy/ttf.rb,
Library/Homebrew/unpack_strategy/xar.rb,
Library/Homebrew/unpack_strategy/zip.rb,
Library/Homebrew/unpack_strategy/gzip.rb,
Library/Homebrew/unpack_strategy/lzip.rb,
Library/Homebrew/unpack_strategy/lzma.rb,
Library/Homebrew/unpack_strategy/bzip2.rb,
Library/Homebrew/unpack_strategy/p7zip.rb,
Library/Homebrew/unpack_strategy/bazaar.rb,
Library/Homebrew/unpack_strategy/fossil.rb,
Library/Homebrew/unpack_strategy/compress.rb,
Library/Homebrew/unpack_strategy/lua_rock.rb,
Library/Homebrew/unpack_strategy/directory.rb,
Library/Homebrew/unpack_strategy/mercurial.rb,
Library/Homebrew/unpack_strategy/executable.rb,
Library/Homebrew/unpack_strategy/subversion.rb,
Library/Homebrew/unpack_strategy/generic_unar.rb,
Library/Homebrew/unpack_strategy/uncompressed.rb,
Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb,
Library/Homebrew/unpack_strategy/microsoft_office_xml.rb,
Library/Homebrew/unpack_strategy/self_extracting_executable.rb
Overview
typed: false frozen_string_literal: true
Defined Under Namespace
Classes: Air, Bazaar, Bzip2, Cab, Compress, Cvs, Directory, Dmg, Executable, Fossil, GenericUnar, Git, Gzip, Jar, Lha, LuaRock, Lzip, Lzma, Mercurial, MicrosoftOfficeXml, Otf, P7Zip, Pax, Pkg, Rar, SelfExtractingExecutable, Sit, Subversion, Tar, Ttf, Uncompressed, Xar, Xz, Zip
Instance Attribute Summary collapse
- #merge_xattrs ⇒ Object readonly private
- #path ⇒ Object readonly private
Class Method Summary collapse
- .detect(path, prioritise_extension: false, type: nil, ref_type: nil, ref: nil, merge_xattrs: nil) ⇒ Object private
- .from_extension(extension) ⇒ Object private
- .from_magic(path) ⇒ Object private
- .from_type(type) ⇒ Object private
Instance Method Summary collapse
- #dependencies ⇒ Object private
- #extract(to: nil, basename: nil, verbose: nil) ⇒ Object private
- #extract_nestedly(to: nil, basename: nil, verbose: false, prioritise_extension: false) ⇒ Object private
- #initialize(path, ref_type: nil, ref: nil, merge_xattrs: nil) ⇒ Object private
Methods included from SystemCommand::Mixin
#system_command, #system_command!
Instance Attribute Details
#merge_xattrs ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
123 124 125 |
# File 'Library/Homebrew/unpack_strategy.rb', line 123 def merge_xattrs @merge_xattrs end |
#path ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
123 124 125 |
# File 'Library/Homebrew/unpack_strategy.rb', line 123 def path @path end |
Class Method Details
.detect(path, prioritise_extension: false, type: nil, ref_type: nil, ref: nil, merge_xattrs: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'Library/Homebrew/unpack_strategy.rb', line 106 def self.detect(path, prioritise_extension: false, type: nil, ref_type: nil, ref: nil, merge_xattrs: nil) strategy = from_type(type) if type if prioritise_extension && path.extname.present? strategy ||= from_extension(path.extname) strategy ||= strategies.select { |s| s < Directory || s == Fossil } .find { |s| s.can_extract?(path) } else strategy ||= from_magic(path) strategy ||= from_extension(path.extname) end strategy ||= Uncompressed strategy.new(path, ref_type: ref_type, ref: ref, merge_xattrs: merge_xattrs) end |
.from_extension(extension) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
96 97 98 99 100 |
# File 'Library/Homebrew/unpack_strategy.rb', line 96 def self.from_extension(extension) strategies.sort_by { |s| s.extensions.map(&:length).max || 0 } .reverse .find { |s| s.extensions.any? { |ext| extension.end_with?(ext) } } end |
.from_magic(path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
102 103 104 |
# File 'Library/Homebrew/unpack_strategy.rb', line 102 def self.from_magic(path) strategies.find { |s| s.can_extract?(path) } end |
.from_type(type) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'Library/Homebrew/unpack_strategy.rb', line 82 def self.from_type(type) type = { naked: :uncompressed, nounzip: :uncompressed, seven_zip: :p7zip, }.fetch(type, type) begin const_get(type.to_s.split("_").map(&:capitalize).join.gsub(/\d+[a-z]/, &:upcase)) rescue NameError nil end end |
Instance Method Details
#dependencies ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
167 168 169 |
# File 'Library/Homebrew/unpack_strategy.rb', line 167 def dependencies [] end |
#extract(to: nil, basename: nil, verbose: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
137 138 139 140 141 142 |
# File 'Library/Homebrew/unpack_strategy.rb', line 137 def extract(to: nil, basename: nil, verbose: nil) basename ||= path.basename unpack_dir = Pathname(to || Dir.pwd). unpack_dir.mkpath extract_to_dir(unpack_dir, basename: Pathname(basename), verbose: verbose || false) end |
#extract_nestedly(to: nil, basename: nil, verbose: false, prioritise_extension: false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'Library/Homebrew/unpack_strategy.rb', line 144 def extract_nestedly(to: nil, basename: nil, verbose: false, prioritise_extension: false) Dir.mktmpdir do |tmp_unpack_dir| tmp_unpack_dir = Pathname(tmp_unpack_dir) extract(to: tmp_unpack_dir, basename: basename, verbose: verbose) children = tmp_unpack_dir.children if children.count == 1 && !children.first.directory? FileUtils.chmod "+rw", children.first, verbose: verbose s = UnpackStrategy.detect(children.first, prioritise_extension: prioritise_extension) s.extract_nestedly(to: to, verbose: verbose, prioritise_extension: prioritise_extension) next end Directory.new(tmp_unpack_dir).extract(to: to, verbose: verbose) FileUtils.chmod_R "+w", tmp_unpack_dir, force: true, verbose: verbose end end |
#initialize(path, ref_type: nil, ref: nil, merge_xattrs: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
125 126 127 128 129 130 |
# File 'Library/Homebrew/unpack_strategy.rb', line 125 def initialize(path, ref_type: nil, ref: nil, merge_xattrs: nil) @path = Pathname(path). @ref_type = ref_type @ref = ref @merge_xattrs = merge_xattrs end |