Class: Sparkleology::FindApplicationCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/sparkleology/find_application_command.rb

Overview

This command class takes an OS X application name, such as ‘Skitch’, and returns the Sparkle RSS feed URL containing the latest update information. Pass the application name to the initializer, and call run.

+Sparkleology::FindApplicationCommand.new('Skitch').run+

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_name) ⇒ FindApplicationCommand

Returns a new instance of FindApplicationCommand.



9
10
11
# File 'lib/sparkleology/find_application_command.rb', line 9

def initialize(app_name)
  @app_name = app_name
end

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



7
8
9
# File 'lib/sparkleology/find_application_command.rb', line 7

def app_name
  @app_name
end

Instance Method Details

#home_pathObject



39
40
41
# File 'lib/sparkleology/find_application_command.rb', line 39

def home_path
  ENV['TEST_HOME'] || ENV['HOME'] || File.expand_path('~')
end

#pathsObject



35
36
37
# File 'lib/sparkleology/find_application_command.rb', line 35

def paths
  ["#{home_path}/Applications", "/Applications"]
end

#plist_pathObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/sparkleology/find_application_command.rb', line 17

def plist_path
  @plist_path ||= begin
    full_app_name = app_name.gsub(/\.app$/,'') + ".app"
    self.paths.
         map { |root_path| File.join(root_path, full_app_name, "Contents/Info.plist") }.
         find { |plist| File.exists?(plist) }
  end || begin
    raise Sparkleology::InvalidApplicationNameException, app_name
  end
end

#runObject



13
14
15
# File 'lib/sparkleology/find_application_command.rb', line 13

def run
  url_for_latest_versions
end

#url_for_latest_versionsObject



28
29
30
31
32
33
# File 'lib/sparkleology/find_application_command.rb', line 28

def url_for_latest_versions
  application_info = Plist::parse_xml(plist_path)
  application_info['SUFeedURL'] || begin
    raise Sparkleology::NonSparkleApplicationException, app_name
  end
end