Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apps in spotlight #188

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.ruby-version
1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

2 changes: 2 additions & 0 deletions Casks/adium.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ class Adium < Cask
homepage 'http://www.adium.im/'
version '1.5.4'
sha1 '4aff5c040143fb8a8176662c1881815c41874bd0'

link :app, 'Adium.app'
end
2 changes: 2 additions & 0 deletions Casks/firefox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ class Firefox < Cask
homepage 'http://www.mozilla.org/en-US/firefox/'
version '19.0.2'
sha1 'b2b64726b2552b9f28c36e8219ff3246a6a15ea4'

link :app, 'Firefox.app'
end
2 changes: 2 additions & 0 deletions Casks/google-chrome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ class GoogleChrome < Cask
homepage 'https://www.google.com/chrome/'
version 'stable-channel'
no_checksum

link :app, 'Google Chrome.app'
end
2 changes: 2 additions & 0 deletions Casks/skitch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ class Skitch < Cask
homepage 'http://evernote.com/skitch/'
version '2.0.5'
sha1 '64d61e76eb8bd2540f84b5d21ee1ac5f93c74a61'

link :app, 'Skitch.app'
end
2 changes: 2 additions & 0 deletions Casks/steam.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ class Steam < Cask
homepage 'http://store.steampowered.com/about/'
version 'stable'
no_checksum

link :app, 'Steam.app'
end
2 changes: 2 additions & 0 deletions Casks/vlc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ class Vlc < Cask
url 'http://downloads.sourceforge.net/project/vlc/2.0.5/macosx/vlc-2.0.5.dmg'
version '2.0.5'
sha1 'f2d3b240d012f9de6b5f1042a43dccca2c90a0e4'

link :app, 'VLC.app'
end
23 changes: 20 additions & 3 deletions lib/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class Cask::CLI; end
end

class Cask
include Cask::Actions
include Cask::DSL
include Cask::Scopes

Expand All @@ -19,7 +18,11 @@ def self.tapspath
end

def self.caskroom
HOMEBREW_PREFIX.join "Caskroom"
@@caskroom ||= Pathname('/opt/homebrew-cask/Caskroom')
end

def self.caskroom=(caskroom)
@@caskroom = caskroom
end

def self.appdir
Expand All @@ -40,7 +43,13 @@ def self.default_tap=(_tap)

def self.init
HOMEBREW_CACHE.mkpath unless HOMEBREW_CACHE.exist?
caskroom.mkpath unless caskroom.exist?
unless caskroom.exist?
ohai "We need to make Caskroom for the first time at #{caskroom}"
ohai "We'll set permissions properly so this is the only time homebrew-cask will ever need sudo"
current_user = ENV['USER']
system "sudo mkdir -p #{caskroom}"
system "sudo chown #{current_user}:staff #{caskroom.parent}"
end
appdir.mkpath unless appdir.exist?
end

Expand Down Expand Up @@ -85,6 +94,14 @@ def installed?
destination_path.exist?
end

def linkable_apps
if linkables.has_key? :app
linkables[:app].map { |app| Pathname.glob("#{destination_path}/**/#{app}").first }
else
Pathname.glob("#{destination_path}/**/*.app")
end
end

def to_s
@title
end
Expand Down
19 changes: 0 additions & 19 deletions lib/cask/actions.rb

This file was deleted.

37 changes: 37 additions & 0 deletions lib/cask/app_linker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class Cask
class AppLinker
def initialize(cask)
@cask = cask
end

def link
@cask.linkable_apps.each do |app|
link_app(app)
end
end

def unlink
@cask.linkable_apps.each do |app|
unlink_app(app)
end
end

def unlink_app(app)
app_path = Cask.appdir.join(app.basename)
app_path.delete if app_path.exist?
end

def remove_app_extension(path)
Pathname(path.to_s.sub(/\.app$/, ''))
end

def link_app(app)
app_path = Cask.appdir.join(app.basename)
if app_path.directory?
ohai "It seems there is already an app at #{app_path}; not linking."
return
end
`ln -s #{app} #{app_path}`
end
end
end
2 changes: 1 addition & 1 deletion lib/cask/cli/linkapps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Cask::CLI::Linkapps
def self.run(*args)
casks_to_link = args.empty? ? Cask.installed : args
casks_to_link.each do |cask_name|
Cask.load(cask_name).linkapps
Cask::AppLinker.new(Cask.load(cask_name)).link
end
end

Expand Down
10 changes: 10 additions & 0 deletions lib/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def version; self.class.version; end

def sums; self.class.sums || []; end

def linkables; self.class.linkables || {}; end

module ClassMethods
def homepage(homepage=nil)
@homepage ||= homepage
Expand All @@ -26,6 +28,14 @@ def version(version=nil)
@version ||= version
end

def linkables
@linkables ||= Hash.new([])
end

def link(type, *files)
linkables[type] += files
end

attr_reader :sums

def md5(md5=nil)
Expand Down
42 changes: 0 additions & 42 deletions test/cask/actions_test.rb

This file was deleted.

50 changes: 50 additions & 0 deletions test/cask/app_linker_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'test_helper'

describe Cask::AppLinker do
describe 'linkapps' do
before do
@caffeine = Cask.load('local-caffeine')
shutup { Cask::Installer.install(@caffeine) }
@app = @caffeine.destination_path/'Caffeine.app'
end

after do
Cask::Installer.uninstall(@caffeine)
end

it "works with an application in the root directory" do
Cask::AppLinker.new(@caffeine).link
TestHelper.valid_alias?(Cask.appdir/'Caffeine.app').must_equal true
end

it "works with an application in a subdir" do
appsubdir = @caffeine.destination_path/'subdir'
appsubdir.mkpath
FileUtils.mv @app, appsubdir
appinsubdir = appsubdir/'Caffeine.app'

Cask::AppLinker.new(@caffeine).link

TestHelper.valid_alias?(Cask.appdir/'Caffeine.app').must_equal true
end

it "only uses linkables when they are specified" do
FileUtils.cp_r @app, @app.sub('Caffeine.app', 'CaffeineAgain.app')

Cask::AppLinker.new(@caffeine).link

TestHelper.valid_alias?(Cask.appdir/'Caffeine.app').must_equal true
TestHelper.valid_alias?(Cask.appdir/'CaffeineAgain.app').must_equal false
end

it "avoids clobbering an existing app by linking over it" do
(Cask.appdir/'Caffeine.app').mkpath

shutup do
Cask::AppLinker.new(@caffeine).link
end

(Cask.appdir/'Caffeine.app').directory?.must_equal true
end
end
end
15 changes: 15 additions & 0 deletions test/cask/cli_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'test_helper'

describe Cask::CLI do
it "lists the taps for casks that show up in two taps" do
Cask::CLI.nice_listing(%w[
phinze-cask/adium
phinze-cask/google-chrome
passcod-cask/adium
]).must_equal(%w[
google-chrome
passcod-cask/adium
phinze-cask/adium
])
end
end
11 changes: 11 additions & 0 deletions test/cask/dsl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,15 @@
flunk("Wanted unexpected method to simply warn, but got exception #{e}")
end
end

it "allows you to specify linkables" do
CaskWithLinkables = Class.new(Cask)
CaskWithLinkables.class_eval do
link :app, 'Foo.app'
link :app, 'Bar.app'
end

instance = CaskWithLinkables.new
instance.linkables[:app].must_equal %w[Foo.app Bar.app]
end
end
32 changes: 13 additions & 19 deletions test/cli/linkapps_test.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
require 'test_helper'

describe Cask::CLI::Linkapps do
it "only links casks mentioned when arguments are provided" do
caffeine = Cask.load('local-caffeine')
transmission = Cask.load('local-transmission')

before do
shutup do
caffeine = Cask.load('local-caffeine')
transmission = Cask.load('local-transmission')

Cask::Installer.install caffeine
Cask::Installer.install transmission

Cask::CLI::Linkapps.run('local-transmission')
end

(Cask.appdir/"Transmission.app").must_be :symlink?
(Cask.appdir/"Caffeine.app").wont_be :symlink?
end

it "links all installed casks when no arguments supplied" do
caffeine = Cask.load('local-caffeine')
transmission = Cask.load('local-transmission')
it "only links casks mentioned when arguments are provided" do
Cask::CLI::Linkapps.run('local-transmission')

shutup do
Cask::Installer.install caffeine
Cask::Installer.install transmission
TestHelper.valid_alias?(Cask.appdir/"Transmission.app").must_equal true
TestHelper.valid_alias?(Cask.appdir/"Caffeine.app").wont_equal true
end

Cask::CLI::Linkapps.run
end
it "links all installed casks when no arguments supplied" do
Cask::CLI::Linkapps.run

(Cask.appdir/"Transmission.app").must_be :symlink?
(Cask.appdir/"Caffeine.app").must_be :symlink?
TestHelper.valid_alias?(Cask.appdir/"Transmission.app").must_equal true
TestHelper.valid_alias?(Cask.appdir/"Caffeine.app").must_equal true
end
end
16 changes: 0 additions & 16 deletions test/cli/list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,4 @@
local-transmission
OUTPUT
end

it "lists the taps for casks that show up in two taps" do
skip("need to move this implementation to an easier to test location")
Cask.stubs(:installed).returns(%w[
phinze-cask/adium
phinze-cask/google-chrome
passcod-cask/adium
])
lambda {
Cask::CLI::List.run
}.must_output <<-OUTPUT.gsub(/^ */, '')
google-chrome
passcod-cask/adium
phinze-cask/adium
OUTPUT
end
end
1 change: 0 additions & 1 deletion test/cli/options_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@

after do
ENV['HOMEBREW_CASK_OPTS'] = nil
Cask.appdir = CANNED_APPDIR
end
end
2 changes: 2 additions & 0 deletions test/support/Casks/local-caffeine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ class LocalCaffeine < Cask
homepage 'http://example.com/local-caffeine'
version '1.2.3'
sha1 'd2fbdad1619934313026fc831e6c6e3dd97ac030'

link :app, 'Caffeine.app'
end

Loading