Sha256: 2af9f4a9beab6dfb61732bcb9e30b9c976230deddf37f9ff8fdfb6baab28f601

Contents?: true

Size: 1.88 KB

Versions: 23

Compression:

Stored size: 1.88 KB

Contents

require 'set'
module Launchy
  #
  # 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 'handles?' that takes a String and returns true if that
  #    class can handle the input.
  class Application
    extend DescendantTracker

    class << self
      # Find the application that handles the given uri.
      #
      # returns the Class that can handle the uri
      def handling( uri )
        klass = find_child( :handles?, uri )
        return klass if klass
        raise ApplicationNotFoundError, "No application found to handle '#{uri}'"
      end

      #
      # Find the given executable in the available paths
      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 ) 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
    end

    attr_reader :host_os_family
    attr_reader :ruby_engine
    attr_reader :runner

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

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

    def run( cmd, *args )
      runner.run( cmd, *args )
    end
  end
end
require 'launchy/applications/browser'

Version data entries

23 entries across 14 versions & 2 rubygems

Version Path
launchy-2.5.2 lib/launchy/application.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/launchy-2.5.0/lib/launchy/application.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/launchy-2.5.0/lib/launchy/application.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/launchy-2.5.0/lib/launchy/application.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/launchy-2.5.0/lib/launchy/application.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/launchy-2.5.0/lib/launchy/application.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/launchy-2.5.0/lib/launchy/application.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/launchy-2.5.0/lib/launchy/application.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/launchy-2.5.0/lib/launchy/application.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/launchy-2.5.0/lib/launchy/application.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/launchy-2.5.0/lib/launchy/application.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/launchy-2.5.0/lib/launchy/application.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/launchy-2.5.0/lib/launchy/application.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/launchy-2.5.0/lib/launchy/application.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/launchy-2.5.0/lib/launchy/application.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/launchy-2.5.0/lib/launchy/application.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/launchy-2.5.0/lib/launchy/application.rb
tdiary-5.1.4 vendor/bundle/ruby/2.7.0/gems/launchy-2.5.0/lib/launchy/application.rb
tdiary-5.1.3 vendor/bundle/ruby/2.6.0/gems/launchy-2.5.0/lib/launchy/application.rb
tdiary-5.1.3 vendor/bundle/ruby/2.7.0/gems/launchy-2.5.0/lib/launchy/application.rb