Spec-Zone.ru › Homebrew

Class: Cask::DSL::Rename Private

Inherits:
Object
  • Object
  • Cask::DSL::Rename
show all
Defined in:
cask/dsl/rename.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Class corresponding to the rename stanza.

Instance Attribute Summary collapse

  • #from ⇒ String readonly private
  • #to ⇒ String readonly private

Instance Method Summary collapse

  • #initialize(from, to) ⇒ void constructor private
  • #pairs ⇒ Hash{Symbol => String} private
  • #perform_rename(staged_path) ⇒ void private

Constructor Details

#initialize(from, to) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • from (String)
  • to (String)


12
13
14
15
# File 'cask/dsl/rename.rb', line 12

def initialize(from, to)
  @from = from
  @to = to
end

Instance Attribute Details

#from ⇒ String (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (String)


9
10
11
# File 'cask/dsl/rename.rb', line 9

def from
  @from
end

#to ⇒ String (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (String)


9
10
11
# File 'cask/dsl/rename.rb', line 9

def to
  @to
end

Instance Method Details

#pairs ⇒ Hash{Symbol => String}

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Hash{Symbol => String})


44
45
46
# File 'cask/dsl/rename.rb', line 44

def pairs
  { from:, to: }
end

#perform_rename(staged_path) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • staged_path (Pathname)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'cask/dsl/rename.rb', line 18

def perform_rename(staged_path)
  return unless staged_path.exist?

  # Find files matching the glob pattern
  matching_files = if @from.include?("*")
    staged_path.glob(@from)
  else
    [staged_path.join(@from)].select(&:exist?)
  end

  return if matching_files.empty?

  # Rename the first matching file to the target path
  source_file = matching_files.first
  return if source_file.nil?

  target_file = staged_path.join(@to)

  # Ensure target directory exists
  target_file.dirname.mkpath

  # Perform the rename
  source_file.rename(target_file.to_s) if source_file.exist?
end

© 2009–present Homebrew contributors
Licensed under the BSD 2-Clause License.
https://docs.brew.sh/rubydoc/Cask/DSL/Rename.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API