aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib
diff options
context:
space:
mode:
authorMarkus Reiter2017-12-03 09:06:23 +0100
committerMarkus Reiter2018-01-27 21:47:18 +0100
commit6760d26319c6fcbf8ba74bd737530adc7831da22 (patch)
treeac7fefe897fa1bc4eb50f74959fb215f292bd441 /Library/Homebrew/cask/lib
parentd558ec09332c74927dfb9182b19e11c5a73d8b52 (diff)
downloadbrew-6760d26319c6fcbf8ba74bd737530adc7831da22.tar.bz2
Create `Hbc::Config` class.
Diffstat (limited to 'Library/Homebrew/cask/lib')
-rw-r--r--Library/Homebrew/cask/lib/hbc.rb1
-rw-r--r--Library/Homebrew/cask/lib/hbc/artifact/relocated.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli.rb26
-rw-r--r--Library/Homebrew/cask/lib/hbc/config.rb65
-rw-r--r--Library/Homebrew/cask/lib/hbc/dsl.rb6
-rw-r--r--Library/Homebrew/cask/lib/hbc/locations.rb82
6 files changed, 81 insertions, 101 deletions
diff --git a/Library/Homebrew/cask/lib/hbc.rb b/Library/Homebrew/cask/lib/hbc.rb
index db036d279..d865b31f2 100644
--- a/Library/Homebrew/cask/lib/hbc.rb
+++ b/Library/Homebrew/cask/lib/hbc.rb
@@ -17,6 +17,7 @@ require "hbc/download_strategy"
require "hbc/exceptions"
require "hbc/installer"
require "hbc/locations"
+require "hbc/config"
require "hbc/macos"
require "hbc/pkg"
require "hbc/qualified_token"
diff --git a/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb b/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb
index 540699630..155d52c06 100644
--- a/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb
+++ b/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb
@@ -19,7 +19,7 @@ module Hbc
end
def self.resolve_target(target)
- Hbc.public_send(dirmethod).join(target)
+ Config.global.public_send(dirmethod).join(target)
end
attr_reader :source, :target
diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb
index 5da2a137a..6410af5ae 100644
--- a/Library/Homebrew/cask/lib/hbc/cli.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli.rb
@@ -49,19 +49,19 @@ module Hbc
include Options
- option "--appdir=PATH", ->(value) { Hbc.appdir = value }
- option "--colorpickerdir=PATH", ->(value) { Hbc.colorpickerdir = value }
- option "--prefpanedir=PATH", ->(value) { Hbc.prefpanedir = value }
- option "--qlplugindir=PATH", ->(value) { Hbc.qlplugindir = value }
- option "--dictionarydir=PATH", ->(value) { Hbc.dictionarydir = value }
- option "--fontdir=PATH", ->(value) { Hbc.fontdir = value }
- option "--servicedir=PATH", ->(value) { Hbc.servicedir = value }
- option "--input_methoddir=PATH", ->(value) { Hbc.input_methoddir = value }
- option "--internet_plugindir=PATH", ->(value) { Hbc.internet_plugindir = value }
- option "--audio_unit_plugindir=PATH", ->(value) { Hbc.audio_unit_plugindir = value }
- option "--vst_plugindir=PATH", ->(value) { Hbc.vst_plugindir = value }
- option "--vst3_plugindir=PATH", ->(value) { Hbc.vst3_plugindir = value }
- option "--screen_saverdir=PATH", ->(value) { Hbc.screen_saverdir = value }
+ option "--appdir=PATH", ->(value) { Config.global.appdir = value }
+ option "--colorpickerdir=PATH", ->(value) { Config.global.colorpickerdir = value }
+ option "--prefpanedir=PATH", ->(value) { Config.global.prefpanedir = value }
+ option "--qlplugindir=PATH", ->(value) { Config.global.qlplugindir = value }
+ option "--dictionarydir=PATH", ->(value) { Config.global.dictionarydir = value }
+ option "--fontdir=PATH", ->(value) { Config.global.fontdir = value }
+ option "--servicedir=PATH", ->(value) { Config.global.servicedir = value }
+ option "--input_methoddir=PATH", ->(value) { Config.global.input_methoddir = value }
+ option "--internet_plugindir=PATH", ->(value) { Config.global.internet_plugindir = value }
+ option "--audio_unit_plugindir=PATH", ->(value) { Config.global.audio_unit_plugindir = value }
+ option "--vst_plugindir=PATH", ->(value) { Config.global.vst_plugindir = value }
+ option "--vst3_plugindir=PATH", ->(value) { Config.global.vst3_plugindir = value }
+ option "--screen_saverdir=PATH", ->(value) { Config.global.screen_saverdir = value }
option "--help", :help, false
diff --git a/Library/Homebrew/cask/lib/hbc/config.rb b/Library/Homebrew/cask/lib/hbc/config.rb
new file mode 100644
index 000000000..43408d53d
--- /dev/null
+++ b/Library/Homebrew/cask/lib/hbc/config.rb
@@ -0,0 +1,65 @@
+module Hbc
+ class Config
+ def self.global
+ @global ||= new
+ end
+
+ attr_reader :binarydir
+
+ def initialize(
+ appdir: "/Applications",
+ prefpanedir: "~/Library/PreferencePanes",
+ qlplugindir: "~/Library/QuickLook",
+ dictionarydir: "~/Library/Dictionaries",
+ fontdir: "~/Library/Fonts",
+ colorpickerdir: "~/Library/ColorPickers",
+ servicedir: "~/Library/Services",
+ input_methoddir: "~/Library/Input Methods",
+ internet_plugindir: "~/Library/Internet Plug-Ins",
+ audio_unit_plugindir: "~/Library/Audio/Plug-Ins/Components",
+ vst_plugindir: "~/Library/Audio/Plug-Ins/VST",
+ vst3_plugindir: "~/Library/Audio/Plug-Ins/VST3",
+ screen_saverdir: "~/Library/Screen Savers"
+ )
+
+ self.appdir = appdir
+ self.prefpanedir = prefpanedir
+ self.qlplugindir = qlplugindir
+ self.dictionarydir = dictionarydir
+ self.fontdir = fontdir
+ self.colorpickerdir = colorpickerdir
+ self.servicedir = servicedir
+ self.input_methoddir = input_methoddir
+ self.internet_plugindir = internet_plugindir
+ self.audio_unit_plugindir = audio_unit_plugindir
+ self.vst_plugindir = vst_plugindir
+ self.vst3_plugindir = vst3_plugindir
+ self.screen_saverdir = screen_saverdir
+
+ # `binarydir` is not customisable.
+ @binarydir = HOMEBREW_PREFIX/"bin"
+ end
+
+ [
+ :appdir,
+ :prefpanedir,
+ :qlplugindir,
+ :dictionarydir,
+ :fontdir,
+ :colorpickerdir,
+ :servicedir,
+ :input_methoddir,
+ :internet_plugindir,
+ :audio_unit_plugindir,
+ :vst_plugindir,
+ :vst3_plugindir,
+ :screen_saverdir,
+ ].each do |dir|
+ attr_reader dir
+
+ define_method(:"#{dir}=") do |path|
+ instance_variable_set(:"@#{dir}", Pathname(path).expand_path)
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/cask/lib/hbc/dsl.rb b/Library/Homebrew/cask/lib/hbc/dsl.rb
index 22f0d2f66..969fc8680 100644
--- a/Library/Homebrew/cask/lib/hbc/dsl.rb
+++ b/Library/Homebrew/cask/lib/hbc/dsl.rb
@@ -292,11 +292,7 @@ module Hbc
end
def appdir
- self.class.appdir
- end
-
- def self.appdir
- Hbc.appdir.sub(%r{\/$}, "")
+ Config.global.appdir
end
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/locations.rb b/Library/Homebrew/cask/lib/hbc/locations.rb
index 5c9a28f5d..40ba2989f 100644
--- a/Library/Homebrew/cask/lib/hbc/locations.rb
+++ b/Library/Homebrew/cask/lib/hbc/locations.rb
@@ -15,88 +15,6 @@ module Hbc
@cache ||= HOMEBREW_CACHE.join("Cask")
end
- attr_writer :appdir
-
- def appdir
- @appdir ||= Pathname.new("/Applications").expand_path
- end
-
- attr_writer :prefpanedir
-
- def prefpanedir
- @prefpanedir ||= Pathname.new("~/Library/PreferencePanes").expand_path
- end
-
- attr_writer :qlplugindir
-
- def qlplugindir
- @qlplugindir ||= Pathname.new("~/Library/QuickLook").expand_path
- end
-
- attr_writer :dictionarydir
-
- def dictionarydir
- @dictionarydir ||= Pathname.new("~/Library/Dictionaries").expand_path
- end
-
- attr_writer :fontdir
-
- def fontdir
- @fontdir ||= Pathname.new("~/Library/Fonts").expand_path
- end
-
- attr_writer :colorpickerdir
-
- def colorpickerdir
- @colorpickerdir ||= Pathname.new("~/Library/ColorPickers").expand_path
- end
-
- attr_writer :servicedir
-
- def servicedir
- @servicedir ||= Pathname.new("~/Library/Services").expand_path
- end
-
- def binarydir
- @binarydir ||= HOMEBREW_PREFIX.join("bin")
- end
-
- attr_writer :input_methoddir
-
- def input_methoddir
- @input_methoddir ||= Pathname.new("~/Library/Input Methods").expand_path
- end
-
- attr_writer :internet_plugindir
-
- def internet_plugindir
- @internet_plugindir ||= Pathname.new("~/Library/Internet Plug-Ins").expand_path
- end
-
- attr_writer :audio_unit_plugindir
-
- def audio_unit_plugindir
- @audio_unit_plugindir ||= Pathname.new("~/Library/Audio/Plug-Ins/Components").expand_path
- end
-
- attr_writer :vst_plugindir
-
- def vst_plugindir
- @vst_plugindir ||= Pathname.new("~/Library/Audio/Plug-Ins/VST").expand_path
- end
-
- attr_writer :vst3_plugindir
-
- def vst3_plugindir
- @vst3_plugindir ||= Pathname.new("~/Library/Audio/Plug-Ins/VST3").expand_path
- end
-
- attr_writer :screen_saverdir
-
- def screen_saverdir
- @screen_saverdir ||= Pathname.new("~/Library/Screen Savers").expand_path
- end
-
attr_writer :default_tap
def default_tap