Class: Launchy::Application

Inherits:
Object
  • Object
show all
Extended by:
DescendantTracker
Defined in:
lib/launchy/application.rb,
lib/launchy/applications/browser.rb

Overview

Application is the base class of all the application types that launchy may invoke. It essentially defines the public api of the launchy system.

Every class that inherits from Application must define:

  1. A constructor taking no parameters

  2. An instance method 'open' taking a string or URI as the first parameter and a hash as the second

  3. A class method 'schemes' that returns an array of Strings containing the schemes that the Application will handle

Direct Known Subclasses

Browser

Defined Under Namespace

Classes: Browser

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DescendantTracker

children, find_child, inherited

Constructor Details

#initializeApplication


66
67
68
69
70
# File 'lib/launchy/application.rb', line 66

def initialize
  @host_os_family = Launchy::Detect::HostOsFamily.detect
  @ruby_engine    = Launchy::Detect::RubyEngine.detect
  @runner         = Launchy::Detect::Runner.detect
end

Instance Attribute Details

#host_os_familyObject (readonly)

Returns the value of attribute host_os_family


63
64
65
# File 'lib/launchy/application.rb', line 63

def host_os_family
  @host_os_family
end

#ruby_engineObject (readonly)

Returns the value of attribute ruby_engine


64
65
66
# File 'lib/launchy/application.rb', line 64

def ruby_engine
  @ruby_engine
end

#runnerObject (readonly)

Returns the value of attribute runner


65
66
67
# File 'lib/launchy/application.rb', line 65

def runner
  @runner
end

Class Method Details

.find_executable(bin, *paths) ⇒ Object

Find the given executable in the available paths


49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/launchy/application.rb', line 49

def find_executable( bin, *paths )
  paths = ENV['PATH'].split( File::PATH_SEPARATOR ) if paths.empty?
  paths.each do |path|
    file = File.join( path, bin )
    if File.executable?( file ) then
      Launchy.log "#{self.name} : found executable #{file}"
      return file
    end
  end
  Launchy.log "#{self.name} : Unable to find `#{bin}' in #{paths.join(", ")}"
  return nil
end

.for_scheme(scheme) ⇒ Object

Find the application that handles the given scheme. May take either a String or something that responds_to?( :scheme )


36
37
38
39
40
41
42
43
44
45
# File 'lib/launchy/application.rb', line 36

def for_scheme( scheme )
  if scheme.respond_to?( :scheme ) then
    scheme = scheme.scheme
  end

  klass = find_child( :handles?, scheme )
  return klass if klass

  raise SchemeNotFoundError, "No application found to handle scheme '#{scheme}'. Known schemes: #{scheme_list.join(", ")}"
end

.handles?(scheme) ⇒ Boolean

if this application handles the given scheme


28
29
30
# File 'lib/launchy/application.rb', line 28

def handles?( scheme )
  schemes.include?( scheme )
end

.scheme_listObject

The list of all the schemes all the applications know


21
22
23
# File 'lib/launchy/application.rb', line 21

def scheme_list
  children.collect { |a| a.schemes }.flatten.sort
end

Instance Method Details

#find_executable(bin, *paths) ⇒ Object


72
73
74
# File 'lib/launchy/application.rb', line 72

def find_executable( bin, *paths )
  Application.find_executable( bin, *paths )
end

#run(cmd, *args) ⇒ Object


76
77
78
# File 'lib/launchy/application.rb', line 76

def run( cmd, *args )
  runner.run( cmd, *args )
end