Remove Cask::Decorator

This commit is contained in:
Federico Bond 2014-08-12 22:15:33 -03:00
parent b58f2b2da2
commit ff0a5c10e3
17 changed files with 63 additions and 66 deletions

View File

@ -18,7 +18,6 @@ require 'cask/cli'
require 'cask/caveats'
require 'cask/conflicts_with'
require 'cask/container'
require 'cask/decorator'
require 'cask/depends_on'
require 'cask/download'
require 'cask/download_strategy'

View File

@ -6,13 +6,13 @@ class Cask::Artifact::AfterBlock < Cask::Artifact::Base
def install_phase
@cask.artifacts[:after_install].each do |block|
Cask::Decorator.new(Cask::DSL::AfterInstall, @cask).instance_eval &block
Cask::DSL::AfterInstall.new(@cask).instance_eval &block
end
end
def uninstall_phase
@cask.artifacts[:after_uninstall].each do |block|
Cask::Decorator.new(Cask::DSL::AfterUninstall, @cask).instance_eval &block
Cask::DSL::AfterUninstall.new(@cask).instance_eval &block
end
end
end

View File

@ -6,13 +6,13 @@ class Cask::Artifact::BeforeBlock < Cask::Artifact::Base
def install_phase
@cask.artifacts[:before_install].each do |block|
Cask::Decorator.new(Cask::DSL::BeforeInstall, @cask).instance_eval &block
Cask::DSL::BeforeInstall.new(@cask).instance_eval &block
end
end
def uninstall_phase
@cask.artifacts[:before_uninstall].each do |block|
Cask::Decorator.new(Cask::DSL::BeforeUninstall, @cask).instance_eval &block
Cask::DSL::BeforeUninstall.new(@cask).instance_eval &block
end
end
end

View File

@ -1,20 +0,0 @@
class Cask::Decorator
def initialize(module_, cask, command = Cask::SystemCommand)
self.extend(module_)
@cask = cask
@command = command
end
def system_command(executable, options = {})
@command.run!(executable, options)
end
def method_missing(m, *args, &block)
if @cask.respond_to?(m)
@cask.send(m, *args, &block)
else
super
end
end
end

View File

@ -3,6 +3,7 @@ require 'set'
module Cask::DSL; end
require 'cask/dsl/base'
require 'cask/dsl/installed'
require 'cask/dsl/after_install'
require 'cask/dsl/after_uninstall'

View File

@ -1,4 +1,4 @@
module Cask::DSL::AfterInstall
class Cask::DSL::AfterInstall < Cask::DSL::Base
include Cask::DSL::Installed
def suppress_move_to_applications

View File

@ -1 +1 @@
module Cask::DSL::AfterUninstall; end
class Cask::DSL::AfterUninstall < Cask::DSL::Base; end

26
lib/cask/dsl/base.rb Normal file
View File

@ -0,0 +1,26 @@
class Cask::DSL::Base
def initialize(cask, command = Cask::SystemCommand)
@cask = cask
@command = command
end
def system_command(executable, options = {})
@command.run!(executable, options)
end
def title
@cask.title
end
def version
@cask.version
end
def caskroom_path
@cask.class.caskroom.join(title)
end
def destination_path
caskroom_path.join(@cask.version.to_s)
end
end

View File

@ -1 +1 @@
module Cask::DSL::BeforeInstall; end
class Cask::DSL::BeforeInstall < Cask::DSL::Base; end

View File

@ -1,4 +1,4 @@
module Cask::DSL::BeforeUninstall
class Cask::DSL::BeforeUninstall < Cask::DSL::Base
include Cask::DSL::Installed
def remove_accessibility_access

View File

@ -1,6 +1,6 @@
module Cask::DSL::Installed
def info_plist
"#{destination_path}/#{artifacts[:link].first.first}/Contents/Info.plist"
"#{destination_path}/#{@cask.artifacts[:link].first.first}/Contents/Info.plist"
end
def plist_exec(cmd)

View File

@ -50,7 +50,7 @@ class Cask::Source::PathBase
# simulate "require"
begin
Cask.const_get(cask_class_name)
Object.const_get(cask_class_name)
rescue NameError
eval(cask_string, TOPLEVEL_BINDING)
end
@ -61,7 +61,7 @@ class Cask::Source::PathBase
raise e
end
begin
Cask.const_get(cask_class_name).new
Object.const_get(cask_class_name).new
rescue CaskError, StandardError, ScriptError => e
# bug: e.message.concat doesn't work with CaskError exceptions
e.message.concat(" while instantiating '#{cask_class_name}' from '#{path}'")

View File

@ -2,7 +2,7 @@ require 'test_helper'
describe Cask::Artifact::AfterBlock do
describe 'install_phase' do
it 'calls the specified block after installing, passing a cask decorator' do
it 'calls the specified block after installing, passing a cask mini-dsl' do
called = false
yielded_arg = nil
@ -18,12 +18,12 @@ describe Cask::Artifact::AfterBlock do
Cask::Artifact::AfterBlock.new(cask).install_phase
called.must_equal true
yielded_arg.must_be_kind_of Cask::Decorator
yielded_arg.must_be_kind_of Cask::DSL::AfterInstall
end
end
describe 'uninstall_phase' do
it 'calls the specified block after uninstalling, passing a cask decorator' do
it 'calls the specified block after uninstalling, passing a cask mini-dsl' do
called = false
yielded_arg = nil
@ -39,7 +39,7 @@ describe Cask::Artifact::AfterBlock do
Cask::Artifact::AfterBlock.new(cask).uninstall_phase
called.must_equal true
yielded_arg.must_be_kind_of Cask::Decorator
yielded_arg.must_be_kind_of Cask::DSL::AfterUninstall
end
end
end

View File

@ -2,7 +2,7 @@ require 'test_helper'
describe Cask::Artifact::BeforeBlock do
describe 'install_phase' do
it 'calls the specified block before installing, passing a cask decorator' do
it 'calls the specified block before installing, passing a cask mini-dsl' do
called = false
yielded_arg = nil
@ -18,12 +18,12 @@ describe Cask::Artifact::BeforeBlock do
Cask::Artifact::BeforeBlock.new(cask).install_phase
called.must_equal true
yielded_arg.must_be_kind_of Cask::Decorator
yielded_arg.must_be_kind_of Cask::DSL::BeforeInstall
end
end
describe 'uninstall_phase' do
it 'calls the specified block before uninstalling, passing a cask decorator' do
it 'calls the specified block before uninstalling, passing a cask mini-dsl' do
called = false
yielded_arg = nil
@ -39,7 +39,7 @@ describe Cask::Artifact::BeforeBlock do
Cask::Artifact::BeforeBlock.new(cask).uninstall_phase
called.must_equal true
yielded_arg.must_be_kind_of Cask::Decorator
yielded_arg.must_be_kind_of Cask::DSL::BeforeUninstall
end
end
end

View File

@ -1,9 +0,0 @@
require 'test_helper'
describe Cask::Decorator do
it "forwards methods to cask" do
cask = Cask.load('basic-cask')
decorator = Cask::Decorator.new(Cask::DSL::BeforeInstall, cask)
decorator.title.must_equal 'basic-cask'
end
end

View File

@ -3,60 +3,60 @@ require "test_helper"
describe Cask::DSL::AfterInstall do
before do
cask = Cask.load('basic-cask')
@decorator = Cask::Decorator.new(Cask::DSL::AfterInstall, cask, Cask::FakeSystemCommand)
@dsl = Cask::DSL::AfterInstall.new(cask, Cask::FakeSystemCommand)
end
it "can run system commands with list-form arguments" do
Cask::FakeSystemCommand.expects_command(
['echo', 'homebrew-cask', 'rocks!']
)
@decorator.system_command("echo", :args => ["homebrew-cask", "rocks!"])
@dsl.system_command("echo", :args => ["homebrew-cask", "rocks!"])
end
it "can get the Info.plist file for the primary app" do
@decorator.info_plist.must_include "basic-cask/1.2.3/TestCask.app/Contents/Info.plist"
@dsl.info_plist.must_include "basic-cask/1.2.3/TestCask.app/Contents/Info.plist"
end
it "can execute commands on the Info.plist file" do
Cask::FakeSystemCommand.expects_command(
['/usr/libexec/PlistBuddy', '-c', 'Print CFBundleIdentifier', @decorator.info_plist]
['/usr/libexec/PlistBuddy', '-c', 'Print CFBundleIdentifier', @dsl.info_plist]
)
@decorator.plist_exec('Print CFBundleIdentifier')
@dsl.plist_exec('Print CFBundleIdentifier')
end
it "can retrieve the bundle identifier for the primary app" do
Cask::FakeSystemCommand.stubs_command(
['/usr/libexec/PlistBuddy', '-c', 'Print CFBundleIdentifier', @decorator.info_plist],
['/usr/libexec/PlistBuddy', '-c', 'Print CFBundleIdentifier', @dsl.info_plist],
"com.example.BasicCask"
)
@decorator.bundle_identifier.must_equal "com.example.BasicCask"
@dsl.bundle_identifier.must_equal "com.example.BasicCask"
end
it "can set a key in the Info.plist file" do
Cask::FakeSystemCommand.expects_command(
['/usr/libexec/PlistBuddy', '-c', 'Set :JVMOptions:JVMVersion 1.6+', @decorator.info_plist]
['/usr/libexec/PlistBuddy', '-c', 'Set :JVMOptions:JVMVersion 1.6+', @dsl.info_plist]
)
@decorator.plist_set(':JVMOptions:JVMVersion', '1.6+')
@dsl.plist_set(':JVMOptions:JVMVersion', '1.6+')
end
it "can suppress move to applications folder alert " do
@decorator.stubs(:bundle_identifier => 'com.example.BasicCask')
@dsl.stubs(:bundle_identifier => 'com.example.BasicCask')
Cask::FakeSystemCommand.expects_command(
['/usr/bin/defaults', 'write', 'com.example.BasicCask', 'moveToApplicationsFolderAlertSuppress', '-bool', 'true']
)
@decorator.suppress_move_to_applications
@dsl.suppress_move_to_applications
end
it "can enable accessibility access" do
MacOS.stubs(:version => OS::Mac::Version.new('10.9'))
@decorator.stubs(:bundle_identifier => 'com.example.BasicCask')
@dsl.stubs(:bundle_identifier => 'com.example.BasicCask')
Cask::FakeSystemCommand.expects_command(
["/usr/bin/sudo", "-E", "--", "sqlite3", "/Library/Application Support/com.apple.TCC/TCC.db", "INSERT INTO access VALUES('kTCCServiceAccessibility','com.example.BasicCask',0,1,1,NULL);"]
)
@decorator.enable_accessibility_access
@dsl.enable_accessibility_access
end
it "can enable accessibility access in OS X versions prior to Mavericks" do
@ -65,6 +65,6 @@ describe Cask::DSL::AfterInstall do
Cask::FakeSystemCommand.expects_command(
['touch', '/private/var/db/.AccessibilityAPIEnabled']
)
@decorator.enable_accessibility_access
@dsl.enable_accessibility_access
end
end

View File

@ -3,17 +3,17 @@ require "test_helper"
describe Cask::DSL::BeforeUninstall do
before do
cask = Cask.load('basic-cask')
@decorator = Cask::Decorator.new(Cask::DSL::BeforeUninstall, cask, Cask::FakeSystemCommand)
@dsl = Cask::DSL::BeforeUninstall.new(cask, Cask::FakeSystemCommand)
end
it "can remove accessibility access" do
MacOS.stubs(:version => OS::Mac::Version.new('10.9'))
@decorator.stubs(:bundle_identifier => 'com.example.BasicCask')
@dsl.stubs(:bundle_identifier => 'com.example.BasicCask')
Cask::FakeSystemCommand.expects_command(
["/usr/bin/sudo", "-E", "--", "sqlite3", "/Library/Application Support/com.apple.TCC/TCC.db", "DELETE FROM access WHERE client='com.example.BasicCask';"]
)
@decorator.remove_accessibility_access
@dsl.remove_accessibility_access
end
end