-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1949 from phinze/arbitrary-block-support
allow casks to support arbitrary blocks
- 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 |