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) ⇒ 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:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'bundle/dsl.rb', line 43

def initialize(path)
  @path = path
  path_read = path.read
  raise "path_read is nil" unless path_read

  @input = T.let(path_read, String)
  @entries = T.let([], T::Array[Entry])
  @cask_arguments = T.let({}, T::Hash[Symbol, T.untyped])

  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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, **options, &block) ⇒ T.untyped

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:

  • method_name (Symbol)
  • args (T.untyped)
  • options (T.untyped)
  • block (T.proc.void, nil)

Returns:

  • (T.untyped)

Raises:

  • (ArgumentError)


136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'bundle/dsl.rb', line 136

def method_missing(method_name, *args, **options, &block)
  extension = Homebrew::Bundle.extension(method_name)
  return super if extension.nil?
  raise ArgumentError, "blocks are not supported for #{method_name}" if block

  # Extension DSL entries follow the existing Brewfile calling convention:
  # a required name plus an optional options hash, passed positionally,
  # with keywords, or both.
  unless (1..2).cover?(args.length)
    raise ArgumentError,
          "wrong number of arguments (given #{args.length}, expected 1..2)"
  end

  positional_options = {}
  if args.length == 2
    positional_options = args[1]
    unless positional_options.is_a? Hash
      raise ArgumentError,
            "options(#{positional_options.inspect}) should be a Hash object"
    end
  end

  @entries << extension.entry(args.first, positional_options.merge(options))
end

Instance Attribute Details

#cask_argumentsHash{Symbol => T.untyped} (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:



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

def cask_arguments
  @cask_arguments
end

#entriesArray<Entry> (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:



34
35
36
# File 'bundle/dsl.rb', line 34

def entries
  @entries
end

#inputString (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:



40
41
42
# File 'bundle/dsl.rb', line 40

def input
  @input
end

Class Method Details

.sanitize_brew_name(name) ⇒ 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.

Parameters:

Returns:



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

def self.sanitize_brew_name(name)
  name = name.downcase
  if name =~ HOMEBREW_CORE_FORMULA_REGEX
    sanitized_name = Regexp.last_match(1)
    raise "sanitized_name is nil" unless sanitized_name

    sanitized_name
  elsif name =~ HOMEBREW_TAP_FORMULA_REGEX
    user = Regexp.last_match(1)
    repo = Regexp.last_match(2)
    name = Regexp.last_match(3)
    raise "repo is nil" unless repo

    "#{user}/#{repo.sub("homebrew-", "")}/#{name}"
  else
    name
  end
end

.sanitize_cask_name(name) ⇒ 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.

Parameters:

Returns:



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

def self.sanitize_cask_name(name)
  Utils.name_from_full_name(name).downcase
end

.sanitize_tap_name(name) ⇒ 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.

Parameters:

Returns:



118
119
120
121
122
123
124
125
# File 'bundle/dsl.rb', line 118

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 = {}) ⇒ 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:



72
73
74
75
# File 'bundle/dsl.rb', line 72

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

#cask(name, options = {}) ⇒ 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:



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

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

#cask_args(args) ⇒ 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:



67
68
69
# File 'bundle/dsl.rb', line 67

def cask_args(args)
  @cask_arguments.merge!(args)
end

#processvoid

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.



62
63
64
# File 'bundle/dsl.rb', line 62

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

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

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:

  • method_name (String, Symbol)
  • include_private (Boolean) (defaults to: false)

Returns:

  • (Boolean)


162
163
164
# File 'bundle/dsl.rb', line 162

def respond_to_missing?(method_name, include_private = false)
  Homebrew::Bundle.extension(method_name).present? || super
end

#tap(name, clone_target = nil, options = {}) ⇒ 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:



87
88
89
90
91
# File 'bundle/dsl.rb', line 87

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