Class: Homebrew::Bundle::Dsl Private
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
- #cask_arguments ⇒ Object readonly private
- #entries ⇒ Object readonly private
- #input ⇒ Object readonly private
Class Method Summary collapse
- .sanitize_brew_name(name) ⇒ Object private
- .sanitize_cask_name(name) ⇒ Object private
- .sanitize_tap_name(name) ⇒ Object private
Instance Method Summary collapse
- #brew(name, options = {}) ⇒ Object private
- #cask(name, options = {}) ⇒ Object private
- #cask_args(args) ⇒ Object private
-
#initialize(path) ⇒ Dsl
constructor
private
A new instance of Dsl.
- #method_missing(method_name, *args, **options, &block) ⇒ Object private
- #process ⇒ Object private
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean private
- #tap(name, clone_target = nil, options = {}) ⇒ Object private
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.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'bundle/dsl.rb', line 34 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.}" 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) ⇒ 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.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'bundle/dsl.rb', line 122 def method_missing(method_name, *args, **, &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 = {} if args.length == 2 = args[1] unless .is_a? Hash raise ArgumentError, "options(#{.inspect}) should be a Hash object" end end @entries << extension.entry(args.first, .merge()) end |
Instance Attribute Details
#cask_arguments ⇒ Object (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.
32 33 34 |
# File 'bundle/dsl.rb', line 32 def cask_arguments @cask_arguments end |
#entries ⇒ Object (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.
32 33 34 |
# File 'bundle/dsl.rb', line 32 def entries @entries end |
#input ⇒ Object (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.
32 33 34 |
# File 'bundle/dsl.rb', line 32 def input @input end |
Class Method Details
.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.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'bundle/dsl.rb', line 92 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 = Regexp.last_match(2) name = Regexp.last_match(3) return name if repo.nil? || name.nil? "#{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.
117 118 119 120 |
# File 'bundle/dsl.rb', line 117 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.
108 109 110 111 112 113 114 115 |
# File 'bundle/dsl.rb', line 108 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.
59 60 61 62 63 64 65 |
# File 'bundle/dsl.rb', line 59 def brew(name, = {}) raise "name(#{name.inspect}) should be a String object" unless name.is_a? String raise "options(#{.inspect}) should be a Hash object" unless .is_a? Hash name = Homebrew::Bundle::Dsl.sanitize_brew_name(name) @entries << Entry.new(:brew, name, ) 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.
67 68 69 70 71 72 73 74 75 |
# File 'bundle/dsl.rb', line 67 def cask(name, = {}) raise "name(#{name.inspect}) should be a String object" unless name.is_a? String raise "options(#{.inspect}) should be a Hash object" unless .is_a? Hash [:full_name] = name name = Homebrew::Bundle::Dsl.sanitize_cask_name(name) [:args] = @cask_arguments.merge .fetch(:args, {}) @entries << Entry.new(:cask, name, ) 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.
53 54 55 56 57 |
# File 'bundle/dsl.rb', line 53 def cask_args(args) raise "cask_args(#{args.inspect}) should be a Hash object" unless args.is_a? Hash @cask_arguments.merge!(args) end |
#process ⇒ 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.
49 50 51 |
# File 'bundle/dsl.rb', line 49 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.
147 148 149 |
# File 'bundle/dsl.rb', line 147 def respond_to_missing?(method_name, include_private = false) Homebrew::Bundle.extension(method_name).present? || super 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.
77 78 79 80 81 82 83 84 85 86 |
# File 'bundle/dsl.rb', line 77 def tap(name, clone_target = nil, = {}) 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 [:clone_target] = clone_target name = Homebrew::Bundle::Dsl.sanitize_tap_name(name) @entries << Entry.new(:tap, name, ) end |