Allow passing down configuration into Cask.

This commit is contained in:
Markus Reiter 2017-12-03 21:21:31 +01:00
parent 6760d26319
commit b4df024625
5 changed files with 10 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -292,7 +292,7 @@ module Hbc
end
def appdir
Config.global.appdir
cask.config.appdir
end
end
end