Class: Homebrew::Bundle::Dsl Private

Inherits:
Object
  • Object
show all
Defined in:
bundle/dsl.rb

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.

Defined Under Namespace

Classes: Entry

Constant Summary collapse

HOMEBREW_TAP_ARGS_REGEX =

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

%r{^([\w-]+)/(homebrew-)?([\w-]+)$}
HOMEBREW_CORE_FORMULA_REGEX =

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

%r{^homebrew/homebrew/([\w+-.@]+)$}i
HOMEBREW_TAP_FORMULA_REGEX =

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

%r{^([\w-]+)/([\w-]+)/([\w+-.@]+)$}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Dsl

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 a new instance of Dsl.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'bundle/dsl.rb', line 23

def initialize(path)
  @path = path
  @input = path.read
  @entries = []
  @cask_arguments = {}

  begin
    process
  # Want to catch all exceptions for e.g. syntax errors.
  rescue Exception => e # rubocop:disable Lint/RescueException
    error_msg = "Invalid Brewfile: #{e.message}"
    raise RuntimeError, error_msg, e.backtrace
  end
end

Instance Attribute Details

#cask_argumentsObject (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.



21
22
23
# File 'bundle/dsl.rb', line 21

def cask_arguments
  @cask_arguments
end

#entriesObject (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.



21
22
23
# File 'bundle/dsl.rb', line 21

def entries
  @entries
end

#inputObject (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.



21
22
23
# File 'bundle/dsl.rb', line 21

def input
  @input
end

Class Method Details

.pluralize_dependency(installed_count) ⇒ Object

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.



129
130
131
# File 'bundle/dsl.rb', line 129

def self.pluralize_dependency(installed_count)
  (installed_count == 1) ? "dependency" : "dependencies"
end

.sanitize_brew_name(name) ⇒ Object

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.



101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'bundle/dsl.rb', line 101

def self.sanitize_brew_name(name)
  name = name.downcase
  if name =~ HOMEBREW_CORE_FORMULA_REGEX
    Regexp.last_match(1)
  elsif name =~ HOMEBREW_TAP_FORMULA_REGEX
    user = Regexp.last_match(1)
    repo = T.must(Regexp.last_match(2))
    name = Regexp.last_match(3)
    "#{user}/#{repo.sub("homebrew-", "")}/#{name}"
  else
    name
  end
end

.sanitize_cask_name(name) ⇒ Object

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.



124
125
126
127
# File 'bundle/dsl.rb', line 124

def self.sanitize_cask_name(name)
  name = name.split("/").last if name.include?("/")
  name.downcase
end

.sanitize_tap_name(name) ⇒ Object

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.



115
116
117
118
119
120
121
122
# File 'bundle/dsl.rb', line 115

def self.sanitize_tap_name(name)
  name = name.downcase
  if name =~ HOMEBREW_TAP_ARGS_REGEX
    "#{Regexp.last_match(1)}/#{Regexp.last_match(3)}"
  else
    name
  end
end

Instance Method Details

#brew(name, options = {}) ⇒ Object

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.



48
49
50
51
52
53
54
# File 'bundle/dsl.rb', line 48

def brew(name, options = {})
  raise "name(#{name.inspect}) should be a String object" unless name.is_a? String
  raise "options(#{options.inspect}) should be a Hash object" unless options.is_a? Hash

  name = Homebrew::Bundle::Dsl.sanitize_brew_name(name)
  @entries << Entry.new(:brew, name, options)
end

#cask(name, options = {}) ⇒ Object

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.



56
57
58
59
60
61
62
63
64
# File 'bundle/dsl.rb', line 56

def cask(name, options = {})
  raise "name(#{name.inspect}) should be a String object" unless name.is_a? String
  raise "options(#{options.inspect}) should be a Hash object" unless options.is_a? Hash

  options[:full_name] = name
  name = Homebrew::Bundle::Dsl.sanitize_cask_name(name)
  options[:args] = @cask_arguments.merge options.fetch(:args, {})
  @entries << Entry.new(:cask, name, options)
end

#cask_args(args) ⇒ Object

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.



42
43
44
45
46
# File 'bundle/dsl.rb', line 42

def cask_args(args)
  raise "cask_args(#{args.inspect}) should be a Hash object" unless args.is_a? Hash

  @cask_arguments = args
end

#mas(name, options = {}) ⇒ Object

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.



66
67
68
69
70
71
72
# File 'bundle/dsl.rb', line 66

def mas(name, options = {})
  id = options[:id]
  raise "name(#{name.inspect}) should be a String object" unless name.is_a? String
  raise "options[:id](#{id}) should be an Integer object" unless id.is_a? Integer

  @entries << Entry.new(:mas, name, id:)
end

#processObject

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.



38
39
40
# File 'bundle/dsl.rb', line 38

def process
  instance_eval(@input, @path.to_s)
end

#tap(name, clone_target = nil, options = {}) ⇒ Object

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.



86
87
88
89
90
91
92
93
94
95
# File 'bundle/dsl.rb', line 86

def tap(name, clone_target = nil, options = {})
  raise "name(#{name.inspect}) should be a String object" unless name.is_a? String
  if clone_target && !clone_target.is_a?(String)
    raise "clone_target(#{clone_target.inspect}) should be nil or a String object"
  end

  options[:clone_target] = clone_target
  name = Homebrew::Bundle::Dsl.sanitize_tap_name(name)
  @entries << Entry.new(:tap, name, options)
end

#vscode(name) ⇒ Object

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.



80
81
82
83
84
# File 'bundle/dsl.rb', line 80

def vscode(name)
  raise "name(#{name.inspect}) should be a String object" unless name.is_a? String

  @entries << Entry.new(:vscode, name)
end

#whalebrew(name) ⇒ Object

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.



74
75
76
77
78
# File 'bundle/dsl.rb', line 74

def whalebrew(name)
  raise "name(#{name.inspect}) should be a String object" unless name.is_a? String

  @entries << Entry.new(:whalebrew, name)
end