Class: Launchy::Application
- Inherits:
-
Object
- Object
- Launchy::Application
- 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:
-
A constructor taking no parameters
-
An instance method ‘open’ taking a string or URI as the first parameter and a hash as the second
-
A class method ‘handles?’ that takes a String and returns true if that class can handle the input.
Direct Known Subclasses
Defined Under Namespace
Classes: Browser
Instance Attribute Summary collapse
-
#host_os_family ⇒ Object
readonly
Returns the value of attribute host_os_family.
-
#ruby_engine ⇒ Object
readonly
Returns the value of attribute ruby_engine.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
Class Method Summary collapse
-
.find_executable(bin, *paths) ⇒ Object
Find the given executable in the available paths.
-
.handling(uri) ⇒ Object
Find the application that handles the given uri.
Instance Method Summary collapse
- #find_executable(bin, *paths) ⇒ Object
-
#initialize ⇒ Application
constructor
A new instance of Application.
- #run(cmd, *args) ⇒ Object
Methods included from DescendantTracker
children, find_child, inherited
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
47 48 49 50 51 |
# File 'lib/launchy/application.rb', line 47 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_family ⇒ Object (readonly)
Returns the value of attribute host_os_family.
43 44 45 |
# File 'lib/launchy/application.rb', line 43 def host_os_family @host_os_family end |
#ruby_engine ⇒ Object (readonly)
Returns the value of attribute ruby_engine.
44 45 46 |
# File 'lib/launchy/application.rb', line 44 def ruby_engine @ruby_engine end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
45 46 47 |
# File 'lib/launchy/application.rb', line 45 def runner @runner end |
Class Method Details
.find_executable(bin, *paths) ⇒ Object
Find the given executable in the available paths
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/launchy/application.rb', line 29 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 |
.handling(uri) ⇒ Object
Find the application that handles the given uri.
returns the Class that can handle the uri
21 22 23 24 25 |
# File 'lib/launchy/application.rb', line 21 def handling( uri ) klass = find_child( :handles?, uri ) return klass if klass raise ApplicationNotFoundError, "No application found to handle '#{uri}'" end |
Instance Method Details
#find_executable(bin, *paths) ⇒ Object
53 54 55 |
# File 'lib/launchy/application.rb', line 53 def find_executable( bin, *paths ) Application.find_executable( bin, *paths ) end |
#run(cmd, *args) ⇒ Object
57 58 59 |
# File 'lib/launchy/application.rb', line 57 def run( cmd, *args ) runner.run( cmd, *args ) end |