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.
-
#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.
-
.for_name(name) ⇒ Object
Find the application with the given name.
-
.handling(uri) ⇒ Object
Find the application that handles the given uri.
-
.has_name?(qname) ⇒ Boolean
Does this class have the given name-like string?.
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.
66 67 68 69 |
# File 'lib/launchy/application.rb', line 66 def initialize @host_os_family = Launchy::Detect::HostOsFamily.detect @runner = Launchy::Runner.new end |
Instance Attribute Details
#host_os_family ⇒ Object (readonly)
Returns the value of attribute host_os_family.
64 65 66 |
# File 'lib/launchy/application.rb', line 64 def host_os_family @host_os_family end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
64 65 66 |
# File 'lib/launchy/application.rb', line 64 def runner @runner end |
Class Method Details
.find_executable(bin, *paths) ⇒ Object
Find the given executable in the available paths
returns the path to the executable or nil if not found
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/launchy/application.rb', line 43 def find_executable(bin, *paths) paths = Launchy.path.split(File::PATH_SEPARATOR) if paths.empty? paths.each do |path| file = File.join(path, bin) if File.executable?(file) Launchy.log "#{name} : found executable #{file}" return file end end Launchy.log "#{name} : Unable to find `#{bin}' in #{paths.join(', ')}" nil end |
.for_name(name) ⇒ Object
Find the application with the given name
returns the Class that has the given name
33 34 35 36 37 38 |
# File 'lib/launchy/application.rb', line 33 def for_name(name) klass = find_child(:has_name?, name) return klass if klass raise ApplicationNotFoundError, "No application found named '#{name}'" end |
.handling(uri) ⇒ Object
Find the application that handles the given uri.
returns the Class that can handle the uri
23 24 25 26 27 28 |
# File 'lib/launchy/application.rb', line 23 def handling(uri) klass = find_child(:handles?, uri) return klass if klass raise ApplicationNotFoundError, "No application found to handle '#{uri}'" end |
.has_name?(qname) ⇒ Boolean
Does this class have the given name-like string?
returns true if the class has the given name
59 60 61 |
# File 'lib/launchy/application.rb', line 59 def has_name?(qname) qname.to_s.downcase == name.split("::").last.downcase end |
Instance Method Details
#find_executable(bin, *paths) ⇒ Object
71 72 73 |
# File 'lib/launchy/application.rb', line 71 def find_executable(bin, *paths) Application.find_executable(bin, *paths) end |
#run(cmd, *args) ⇒ Object
75 76 77 |
# File 'lib/launchy/application.rb', line 75 def run(cmd, *args) runner.run(cmd, *args) end |