Class: Cask::DSL Private
- Inherits:
-
Object
- Object
- Cask::DSL
- Defined in:
- Library/Homebrew/cask/dsl.rb,
Library/Homebrew/cask/dsl/base.rb,
Library/Homebrew/cask/dsl/appcast.rb,
Library/Homebrew/cask/dsl/caveats.rb,
Library/Homebrew/cask/dsl/version.rb,
Library/Homebrew/cask/dsl/container.rb,
Library/Homebrew/cask/dsl/preflight.rb,
Library/Homebrew/cask/dsl/depends_on.rb,
Library/Homebrew/cask/dsl/postflight.rb,
Library/Homebrew/cask/dsl/conflicts_with.rb,
Library/Homebrew/cask/dsl/uninstall_preflight.rb,
Library/Homebrew/cask/dsl/uninstall_postflight.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Class representing the domain-specific language used for casks.
Defined Under Namespace
Classes: Appcast, Base, Caveats, ConflictsWith, Container, DependsOn, Postflight, Preflight, UninstallPostflight, UninstallPreflight, Version
Constant Summary collapse
- ORDINARY_ARTIFACT_CLASSES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ Artifact::Installer, Artifact::App, Artifact::Artifact, Artifact::AudioUnitPlugin, Artifact::Binary, Artifact::Colorpicker, Artifact::Dictionary, Artifact::Font, Artifact::InputMethod, Artifact::InternetPlugin, Artifact::Manpage, Artifact::Pkg, Artifact::Prefpane, Artifact::Qlplugin, Artifact::Mdimporter, Artifact::ScreenSaver, Artifact::Service, Artifact::StageOnly, Artifact::Suite, Artifact::VstPlugin, Artifact::Vst3Plugin, Artifact::Uninstall, Artifact::Zap, ].freeze
- ACTIVATABLE_ARTIFACT_CLASSES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
(ORDINARY_ARTIFACT_CLASSES - [Artifact::StageOnly]).freeze
- ARTIFACT_BLOCK_CLASSES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ Artifact::PreflightBlock, Artifact::PostflightBlock, ].freeze
- DSL_METHODS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Set.new([ :appcast, :artifacts, :auto_updates, :caveats, :conflicts_with, :container, :desc, :depends_on, :homepage, :language, :languages, :name, :sha256, :staged_path, :url, :version, :appdir, *ORDINARY_ARTIFACT_CLASSES.map(&:dsl_key), *ACTIVATABLE_ARTIFACT_CLASSES.map(&:dsl_key), *ARTIFACT_BLOCK_CLASSES.flat_map { |klass| [klass.dsl_key, klass.uninstall_dsl_key] }, ]).freeze
Instance Attribute Summary collapse
- #cask ⇒ Object readonly private
- #token ⇒ Object readonly private
Instance Method Summary collapse
- #appcast(*args) ⇒ Object private
-
#appdir ⇒ Object
private
rubocop:enable Style/MissingRespondToMissing.
- #artifacts ⇒ Object private
- #auto_updates(auto_updates = nil) ⇒ Object private
- #caskroom_path ⇒ Object private
- #caveats(*strings, &block) ⇒ Object private
- #conflicts_with(*args) ⇒ Object private
- #container(*args) ⇒ Object private
-
#depends_on(*args) ⇒ Object
private
depends_on
uses a load method so that multiple stanzas can be merged. - #desc(description = nil) ⇒ Object private
- #homepage(homepage = nil) ⇒ Object private
-
#initialize(cask) ⇒ DSL
constructor
private
A new instance of DSL.
- #language(*args, default: false, &block) ⇒ Object private
- #language_eval ⇒ Object private
- #languages ⇒ Object private
-
#method_missing(method) ⇒ Object
private
No need to define it as it's the default/superclass implementation.
- #name(*args) ⇒ Object private
- #set_unique_stanza(stanza, should_return) ⇒ Object private
- #sha256(arg = nil) ⇒ Object private
- #staged_path ⇒ Object private
- #url(*args) ⇒ Object private
- #version(arg = nil) ⇒ Object private
Constructor Details
#initialize(cask) ⇒ DSL
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of DSL.
90 91 92 93 |
# File 'Library/Homebrew/cask/dsl.rb', line 90 def initialize(cask) @cask = cask @token = cask.token end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
No need to define it as it's the default/superclass implementation. rubocop:disable Style/MissingRespondToMissing
291 292 293 294 295 296 297 298 |
# File 'Library/Homebrew/cask/dsl.rb', line 291 def method_missing(method, *) if method Utils.(method, token) nil else super end end |
Instance Attribute Details
#cask ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
88 89 90 |
# File 'Library/Homebrew/cask/dsl.rb', line 88 def cask @cask end |
#token ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
88 89 90 |
# File 'Library/Homebrew/cask/dsl.rb', line 88 def token @token end |
Instance Method Details
#appcast(*args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
185 186 187 |
# File 'Library/Homebrew/cask/dsl.rb', line 185 def appcast(*args) set_unique_stanza(:appcast, args.empty?) { DSL::Appcast.new(*args) } end |
#appdir ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
rubocop:enable Style/MissingRespondToMissing
301 302 303 |
# File 'Library/Homebrew/cask/dsl.rb', line 301 def appdir cask.config.appdir end |
#artifacts ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
233 234 235 |
# File 'Library/Homebrew/cask/dsl.rb', line 233 def artifacts @artifacts ||= SortedSet.new end |
#auto_updates(auto_updates = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
262 263 264 |
# File 'Library/Homebrew/cask/dsl.rb', line 262 def auto_updates(auto_updates = nil) set_unique_stanza(:auto_updates, auto_updates.nil?) { auto_updates } end |
#caskroom_path ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
237 238 239 |
# File 'Library/Homebrew/cask/dsl.rb', line 237 def caskroom_path cask.caskroom_path end |
#caveats(*strings, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'Library/Homebrew/cask/dsl.rb', line 248 def caveats(*strings, &block) @caveats ||= DSL::Caveats.new(cask) if block_given? @caveats.eval_caveats(&block) elsif strings.any? strings.each do |string| @caveats.eval_caveats { string } end else return @caveats.to_s end @caveats end |
#conflicts_with(*args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
228 229 230 231 |
# File 'Library/Homebrew/cask/dsl.rb', line 228 def conflicts_with(*args) # TODO: remove this constraint, and instead merge multiple conflicts_with stanzas set_unique_stanza(:conflicts_with, args.empty?) { DSL::ConflictsWith.new(*args) } end |
#container(*args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
189 190 191 192 193 |
# File 'Library/Homebrew/cask/dsl.rb', line 189 def container(*args) set_unique_stanza(:container, args.empty?) do DSL::Container.new(*args) end end |
#depends_on(*args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
depends_on
uses a load method so that multiple stanzas can be merged.
216 217 218 219 220 221 222 223 224 225 226 |
# File 'Library/Homebrew/cask/dsl.rb', line 216 def depends_on(*args) @depends_on ||= DSL::DependsOn.new return @depends_on if args.empty? begin @depends_on.load(*args) rescue RuntimeError => e raise CaskInvalidError.new(cask, e) end @depends_on end |
#desc(description = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
102 103 104 |
# File 'Library/Homebrew/cask/dsl.rb', line 102 def desc(description = nil) set_unique_stanza(:desc, description.nil?) { description } end |
#homepage(homepage = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
120 121 122 |
# File 'Library/Homebrew/cask/dsl.rb', line 120 def homepage(homepage = nil) set_unique_stanza(:homepage, homepage.nil?) { homepage } end |
#language(*args, default: false, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'Library/Homebrew/cask/dsl.rb', line 124 def language(*args, default: false, &block) if args.empty? language_eval elsif block_given? @language_blocks ||= {} @language_blocks[args] = block return unless default unless @language_blocks.default.nil? raise CaskInvalidError.new(cask, "Only one default language may be defined.") end @language_blocks.default = block else raise CaskInvalidError.new(cask, "No block given to language stanza.") end end |
#language_eval ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'Library/Homebrew/cask/dsl.rb', line 143 def language_eval return @language if defined?(@language) return @language = nil if @language_blocks.nil? || @language_blocks.empty? raise CaskInvalidError.new(cask, "No default language specified.") if @language_blocks.default.nil? locales = cask.config.languages .map do |language| Locale.parse(language) rescue Locale::ParserError nil end .compact locales.each do |locale| key = locale.detect(@language_blocks.keys) next if key.nil? return @language = @language_blocks[key].call end @language = @language_blocks.default.call end |
#languages ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
169 170 171 172 173 |
# File 'Library/Homebrew/cask/dsl.rb', line 169 def languages return [] if @language_blocks.nil? @language_blocks.keys.flatten end |
#name(*args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
95 96 97 98 99 100 |
# File 'Library/Homebrew/cask/dsl.rb', line 95 def name(*args) @name ||= [] return @name if args.empty? @name.concat(args.flatten) end |
#set_unique_stanza(stanza, should_return) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'Library/Homebrew/cask/dsl.rb', line 106 def set_unique_stanza(stanza, should_return) return instance_variable_get("@#{stanza}") if should_return if instance_variable_defined?("@#{stanza}") raise CaskInvalidError.new(cask, "'#{stanza}' stanza may only appear once.") end instance_variable_set("@#{stanza}", yield) rescue CaskInvalidError raise rescue => e raise CaskInvalidError.new(cask, "'#{stanza}' stanza failed with: #{e}") end |
#sha256(arg = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
205 206 207 208 209 210 211 212 213 |
# File 'Library/Homebrew/cask/dsl.rb', line 205 def sha256(arg = nil) set_unique_stanza(:sha256, arg.nil?) do if !arg.is_a?(String) && arg != :no_check raise CaskInvalidError.new(cask, "invalid 'sha256' value: '#{arg.inspect}'") end arg end end |
#staged_path ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
241 242 243 244 245 246 |
# File 'Library/Homebrew/cask/dsl.rb', line 241 def staged_path return @staged_path if @staged_path cask_version = version || :unknown @staged_path = caskroom_path.join(cask_version.to_s) end |
#url(*args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
175 176 177 178 179 180 181 182 183 |
# File 'Library/Homebrew/cask/dsl.rb', line 175 def url(*args) set_unique_stanza(:url, args.empty? && !block_given?) do if block_given? LazyObject.new { URL.new(*yield) } else URL.new(*args) end end end |
#version(arg = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
195 196 197 198 199 200 201 202 203 |
# File 'Library/Homebrew/cask/dsl.rb', line 195 def version(arg = nil) set_unique_stanza(:version, arg.nil?) do if !arg.is_a?(String) && arg != :latest raise CaskInvalidError.new(cask, "invalid 'version' value: '#{arg.inspect}'") end DSL::Version.new(arg) end end |