forked from Homebrew/homebrew-cask
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow casks to support arbitrary blocks
this allows us to experiment with behavior that we may not want to promote to an official feature just yet. i'm thinking about stuff like Homebrew#544, and other things i can't foresee we'll have to be careful to not let this get out of hand, but i think it could be helpful for cask authors to be able to try and problem solve locally.
- Loading branch information
Showing
4 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Cask::Artifact::Block < Cask::Artifact::Base | ||
def self.me?(cask) | ||
cask.artifacts[:after_install].any? || | ||
cask.artifacts[:after_uninstall].any? | ||
end | ||
|
||
def install | ||
@cask.artifacts[:after_install].each { |block| block.call(@cask) } | ||
end | ||
|
||
def uninstall | ||
@cask.artifacts[:after_uninstall].each { |block| block.call(@cask) } | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'test_helper' | ||
|
||
describe Cask::Artifact::Block do | ||
describe 'install' do | ||
it 'calls the specified block after installing, passing the cask' do | ||
called = false | ||
yielded_arg = nil | ||
|
||
CaskWithAfterInstall = Class.new(Cask) | ||
CaskWithAfterInstall.class_eval do | ||
after_install do |c| | ||
called = true | ||
yielded_arg = c | ||
end | ||
end | ||
|
||
cask = CaskWithAfterInstall.new | ||
Cask::Artifact::Block.new(cask).install | ||
|
||
called.must_equal true | ||
yielded_arg.must_equal cask | ||
end | ||
end | ||
|
||
describe 'uninstall' do | ||
it 'calls the specified block after uninstalling, passing the cask' do | ||
called = false | ||
yielded_arg = nil | ||
|
||
CaskWithAfterUninstall = Class.new(Cask) | ||
CaskWithAfterUninstall.class_eval do | ||
after_uninstall do |c| | ||
called = true | ||
yielded_arg = c | ||
end | ||
end | ||
|
||
cask = CaskWithAfterUninstall.new | ||
Cask::Artifact::Block.new(cask).uninstall | ||
|
||
called.must_equal true | ||
yielded_arg.must_equal cask | ||
end | ||
end | ||
end |