Launchy

The entry point into Launchy. This is the sole supported public API.

Launchy.open( uri, options = {} )

The currently defined global options are:

:debug        Turn on debugging output
:application  Explicitly state what application class is going to be used
:host_os      Explicitly state what host operating system to pretend to be
:ruby_engine  Explicitly state what ruby engine to pretend to be under
:dry_run      Do nothing and print the command that would be executed on $stdout

Other options may be used, and those will be passed directly to the application class

Constants

VERSION

Public Class Methods

app_for_uri( uri ) click to toggle source
# File lib/launchy.rb, line 37
def app_for_uri( uri )
  Launchy::Application.handling( uri )
end
app_for_uri_string( s ) click to toggle source
# File lib/launchy.rb, line 41
def app_for_uri_string( s )
  app_for_uri(  string_to_uri( s ) )
end
application() click to toggle source
# File lib/launchy.rb, line 82
def application
  @application || ENV['LAUNCHY_APPLICATION']
end
application=( app ) click to toggle source
# File lib/launchy.rb, line 78
def application=( app )
  @application = app
end
bug_report_message() click to toggle source
# File lib/launchy.rb, line 110
def bug_report_message
  "Please rerun with environment variable LAUNCHY_DEBUG=true or the '-d' commandline option and file a bug at https://github.com/copiousfreetime/launchy/issues/new"
end
debug=( d ) click to toggle source
# File lib/launchy.rb, line 68
def debug=( d )
  @debug = (d == "true")
end
debug?() click to toggle source

we may do logging before a call to ‘open’, hence the need to check LAUNCHY_DEBUG here

# File lib/launchy.rb, line 74
def debug?
  @debug || (ENV['LAUNCHY_DEBUG'] == 'true')
end
dry_run=( dry_run ) click to toggle source
# File lib/launchy.rb, line 102
def dry_run=( dry_run )
  @dry_run = dry_run
end
dry_run?() click to toggle source
# File lib/launchy.rb, line 106
def dry_run?
  @dry_run
end
extract_global_options( options ) click to toggle source
# File lib/launchy.rb, line 60
def extract_global_options( options )
  Launchy.debug        = options.delete( :debug       ) || ENV['LAUNCHY_DEBUG']
  Launchy.application  = options.delete( :application ) || ENV['LAUNCHY_APPLICATION']
  Launchy.host_os      = options.delete( :host_os     ) || ENV['LAUNCHY_HOST_OS']
  Launchy.ruby_engine  = options.delete( :ruby_engine ) || ENV['LAUNCHY_RUBY_ENGINE']
  Launchy.dry_run      = options.delete( :dry_run     ) || ENV['LAUNCHY_DRY_RUN']
end
host_os() click to toggle source
# File lib/launchy.rb, line 90
def host_os
  @host_os || ENV['LAUNCHY_HOST_OS']
end
host_os=( host_os ) click to toggle source
# File lib/launchy.rb, line 86
def host_os=( host_os )
  @host_os = host_os
end
log(msg) click to toggle source
# File lib/launchy.rb, line 114
def log(msg)
  $stderr.puts "LAUNCHY_DEBUG: #{msg}" if Launchy.debug?
end
open(uri_s, options = {} ) click to toggle source

Launch an application for the given uri string

# File lib/launchy.rb, line 25
def open(uri_s, options = {} )
  extract_global_options( options )
  uri = string_to_uri( uri_s )
  app = app_for_uri( uri )
  app.new.open( uri, options )
rescue Launchy::Error => le
  raise le
rescue Exception => e
  msg = "Failure in opening uri #{uri_s.inspect} with options #{options.inspect}: #{e}"
  raise Launchy::Error, msg
end
reset_global_options() click to toggle source
# File lib/launchy.rb, line 52
def reset_global_options
  Launchy.debug       = false
  Launchy.application = nil
  Launchy.host_os     = nil
  Launchy.ruby_engine = nil
  Launchy.dry_run     = false
end
ruby_engine() click to toggle source
# File lib/launchy.rb, line 98
def ruby_engine
  @ruby_engine || ENV['LAUNCHY_RUBY_ENGINE']
end
ruby_engine=( ruby_engine ) click to toggle source
# File lib/launchy.rb, line 94
def ruby_engine=( ruby_engine )
  @ruby_engine = ruby_engine
end
string_to_uri( s ) click to toggle source
# File lib/launchy.rb, line 45
def string_to_uri( s )
  uri = Addressable::URI.parse( s )
  uri = Addressable::URI.heuristic_parse( s ) unless uri.scheme
  raise Launchy::ArgumentError, "Invalid URI given: #{s.inspect}" unless uri
  return uri
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.