From b4df0246256519cf3879263eb7447cfcd5498491 Mon Sep 17 00:00:00 2001 From: Markus Reiter <me@reitermark.us> Date: Sun, 3 Dec 2017 21:21:31 +0100 Subject: [PATCH] Allow passing down configuration into Cask. --- Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb | 3 ++- Library/Homebrew/cask/lib/hbc/artifact/artifact.rb | 2 +- Library/Homebrew/cask/lib/hbc/artifact/relocated.rb | 6 +++--- Library/Homebrew/cask/lib/hbc/cask.rb | 5 +++-- Library/Homebrew/cask/lib/hbc/dsl.rb | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb index f9f736662f..0771054689 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb @@ -95,10 +95,11 @@ module Hbc [executable, arguments] end - attr_reader :cask + attr_reader :cask, :config def initialize(cask) @cask = cask + @config = cask.config end def to_s diff --git a/Library/Homebrew/cask/lib/hbc/artifact/artifact.rb b/Library/Homebrew/cask/lib/hbc/artifact/artifact.rb index 0f37afaded..b7df4b0bd0 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/artifact.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/artifact.rb @@ -25,7 +25,7 @@ module Hbc new(cask, source_string, **target_hash) end - def self.resolve_target(target) + def resolve_target(target) Pathname(target) end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb b/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb index 155d52c062..9195d889a7 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb @@ -18,8 +18,8 @@ module Hbc new(cask, source_string, **target_hash) end - def self.resolve_target(target) - Config.global.public_send(dirmethod).join(target) + def resolve_target(target) + config.public_send(self.class.dirmethod).join(target) end attr_reader :source, :target @@ -32,7 +32,7 @@ module Hbc source = cask.staged_path.join(source) @source = source target ||= source.basename - @target = self.class.resolve_target(target) + @target = resolve_target(target) end def to_a diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index df885371a9..681130c1b1 100644 --- a/Library/Homebrew/cask/lib/hbc/cask.rb +++ b/Library/Homebrew/cask/lib/hbc/cask.rb @@ -6,17 +6,18 @@ module Hbc extend Forwardable include Metadata - attr_reader :token, :sourcefile_path + attr_reader :token, :sourcefile_path, :config def tap return super if block_given? # Object#tap @tap end - def initialize(token, sourcefile_path: nil, tap: nil, &block) + def initialize(token, sourcefile_path: nil, tap: nil, config: Config.global, &block) @token = token @sourcefile_path = sourcefile_path @tap = tap + @config = config @dsl = DSL.new(self) return unless block_given? @dsl.instance_eval(&block) diff --git a/Library/Homebrew/cask/lib/hbc/dsl.rb b/Library/Homebrew/cask/lib/hbc/dsl.rb index 969fc86806..9a88f1b624 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl.rb @@ -292,7 +292,7 @@ module Hbc end def appdir - Config.global.appdir + cask.config.appdir end end end -- GitLab