Module: FileUtils

Defined in:
ext/sass/file_utils.rb

Overview

This is a FileUtils extension that defines several additional commands to be added to the FileUtils utility functions.

Instance Method Summary collapse

Instance Method Details

#fetch(source_uri, dest_path = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'ext/sass/file_utils.rb', line 16

def fetch(source_uri, dest_path = nil)
  dest_path = File.basename(source_uri) if dest_path.nil?

  Rake.rake_output_message "fetch #{source_uri}" if Rake::FileUtilsExt.verbose_flag

  unless Rake::FileUtilsExt.nowrite_flag
    data = Utils.fetch_https(source_uri)
    Gem.write_binary(dest_path, data)
  end

  dest_path
end

#gem_install(name, version, platform) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'ext/sass/file_utils.rb', line 29

def gem_install(name, version, platform)
  require 'rubygems/remote_fetcher'

  install_dir = File.absolute_path('ruby')

  if Rake::FileUtilsExt.verbose_flag
    Rake.rake_output_message [
      'gem', 'install',
      '--force',
      '--install-dir', install_dir,
      '--no-document', '--ignore-dependencies',
      '--platform', platform,
      '--version', version,
      'sass-embedded'
    ].join(' ')
  end

  dependency = Gem::Dependency.new(name, version)

  dependency_request = Gem::Resolver::DependencyRequest.new(dependency, nil)

  resolver_spec = Gem::Resolver::BestSet.new.find_all(dependency_request).find do |s|
    s.platform == platform
  end

  raise Gem::UnsatisfiableDependencyError, dependency_request if resolver_spec.nil?

  options = { force: true, install_dir: }
  if Rake::FileUtilsExt.nowrite_flag
    installer = Gem::Installer.for_spec(resolver_spec.spec, options)
  else
    path = resolver_spec.download(options)
    installer = Gem::Installer.at(path, options)
    installer.install
  end

  yield installer
ensure
  rm_rf install_dir unless Rake::FileUtilsExt.nowrite_flag
end

#gh_attestation_verify(path, repo:, hostname: 'github.com') ⇒ Object



70
71
72
73
74
# File 'ext/sass/file_utils.rb', line 70

def gh_attestation_verify(path, repo:, hostname: 'github.com')
  if SassConfig.development? && system('gh', 'auth', 'status', '--hostname', hostname, %i[out err] => File::NULL)
    sh 'gh', 'attestation', 'verify', path, '--hostname', hostname, '--repo', repo
  end
end

#unarchive(archive, chdir: '.') ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'ext/sass/file_utils.rb', line 6

def unarchive(archive, chdir: '.')
  if Gem.win_platform?
    sh File.absolute_path('tar.exe', Utils.windows_system_directory), '-vxf', archive, '-C', chdir
  elsif archive.downcase.end_with?('.zip')
    sh 'unzip', '-od', chdir, archive
  else
    sh 'tar', '-vxf', archive, '-C', chdir, '--no-same-owner', '--no-same-permissions'
  end
end