aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorMarkus Reiter2017-08-05 15:56:34 +0200
committerMarkus Reiter2017-08-05 16:19:50 +0200
commit67327c75b56cbf9ab8a506879846118b9d3526ab (patch)
treed657f1edb45cb3691ed2d96f1667baeb3eff00c3 /Library/Homebrew
parent42cfb6d238b7b37b8114e9d0c988bc8e47c5c604 (diff)
downloadbrew-67327c75b56cbf9ab8a506879846118b9d3526ab.tar.bz2
Implement `conflicts_with :cask`.
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/cask/lib/hbc/dsl/conflicts_with.rb19
-rw-r--r--Library/Homebrew/cask/lib/hbc/exceptions.rb13
-rw-r--r--Library/Homebrew/cask/lib/hbc/installer.rb17
3 files changed, 37 insertions, 12 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/dsl/conflicts_with.rb b/Library/Homebrew/cask/lib/hbc/dsl/conflicts_with.rb
index 948348239..dfaa55a5c 100644
--- a/Library/Homebrew/cask/lib/hbc/dsl/conflicts_with.rb
+++ b/Library/Homebrew/cask/lib/hbc/dsl/conflicts_with.rb
@@ -10,25 +10,20 @@ module Hbc
:java,
]
- attr_accessor(*VALID_KEYS)
- attr_accessor :pairs
+ attr_reader *VALID_KEYS
def initialize(pairs = {})
@pairs = pairs
+
+ VALID_KEYS.each do |key|
+ instance_variable_set("@#{key}", Set.new)
+ end
+
pairs.each do |key, value|
raise "invalid conflicts_with key: '#{key.inspect}'" unless VALID_KEYS.include?(key)
- writer_method = "#{key}=".to_sym
- send(writer_method, value)
+ instance_variable_set("@#{key}", instance_variable_get("@#{key}").merge([*value]))
end
end
-
- def to_yaml
- @pairs.to_yaml
- end
-
- def to_s
- @pairs.inspect
- end
end
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/exceptions.rb b/Library/Homebrew/cask/lib/hbc/exceptions.rb
index 1a246be65..f7f9e43b6 100644
--- a/Library/Homebrew/cask/lib/hbc/exceptions.rb
+++ b/Library/Homebrew/cask/lib/hbc/exceptions.rb
@@ -17,6 +17,19 @@ module Hbc
end
end
+ class CaskConflictError < AbstractCaskErrorWithToken
+ attr_reader :conflicting_cask
+
+ def initialize(token, conflicting_cask)
+ super(token)
+ @conflicting_cask = conflicting_cask
+ end
+
+ def to_s
+ "Cask '#{token}' conflicts with '#{conflicting_cask}'."
+ end
+ end
+
class CaskUnavailableError < AbstractCaskErrorWithToken
def to_s
"Cask '#{token}' is unavailable" << (reason.empty? ? "." : ": #{reason}")
diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb
index 53210ed4b..37cc4e561 100644
--- a/Library/Homebrew/cask/lib/hbc/installer.rb
+++ b/Library/Homebrew/cask/lib/hbc/installer.rb
@@ -86,6 +86,8 @@ module Hbc
raise CaskAlreadyInstalledError, @cask
end
+ check_conflicts
+
print_caveats
fetch
uninstall_existing_cask if @reinstall
@@ -98,6 +100,21 @@ module Hbc
puts summary
end
+ def check_conflicts
+ return unless @cask.conflicts_with
+
+ @cask.conflicts_with.cask.each do |conflicting_cask|
+ begin
+ conflicting_cask = CaskLoader.load(conflicting_cask)
+ if conflicting_cask.installed?
+ raise CaskConflictError.new(@cask, conflicting_cask)
+ end
+ rescue CaskUnavailableError
+ next # Ignore conflicting Casks that do not exist.
+ end
+ end
+ end
+
def reinstall
odebug "Hbc::Installer#reinstall"
@reinstall = true