Module: Launchy

Defined in:
lib/launchy.rb,
lib/launchy/cli.rb,
lib/launchy/error.rb,
lib/launchy/detect.rb,
lib/launchy/version.rb,
lib/launchy/os_family.rb,
lib/launchy/deprecated.rb,
lib/launchy/application.rb,
lib/launchy/descendant_tracker.rb

Overview

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

Defined Under Namespace

Modules: DescendantTracker, Detect, Version Classes: Application, ApplicationNotFoundError, Browser, Cli, Error, OSFamily

Constant Summary collapse

VERSION =
"2.0.6"

Class Method Summary collapse

Class Method Details

.applicationObject



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

def application
  @application || ENV['LAUNCHY_APPLICATION']
end

.application=(app) ⇒ Object



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

def application=( app )
  @application = app
end

.bug_report_messageObject



99
100
101
# File 'lib/launchy.rb', line 99

def bug_report_message
  "Please file a bug at https://github.com/copiousfreetime/launchy/issues/new"
end

.debug=(d) ⇒ Object



57
58
59
# File 'lib/launchy.rb', line 57

def debug=( d )
  @debug = (d == "true")
end

.debug?Boolean

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

Returns:

  • (Boolean)


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

def debug?
  @debug || (ENV['LAUNCHY_DEBUG'] == 'true')
end

.dry_run=(dry_run) ⇒ Object



91
92
93
# File 'lib/launchy.rb', line 91

def dry_run=( dry_run )
  @dry_run = dry_run
end

.dry_run?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/launchy.rb', line 95

def dry_run?
  @dry_run
end

.extract_global_options(options) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/launchy.rb', line 49

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_osObject



79
80
81
# File 'lib/launchy.rb', line 79

def host_os
  @host_os || ENV['LAUNCHY_HOST_OS']
end

.host_os=(host_os) ⇒ Object



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

def host_os=( host_os )
  @host_os = host_os
end

.log(msg) ⇒ Object



103
104
105
# File 'lib/launchy.rb', line 103

def log(msg)
  $stderr.puts "LAUNCHY_DEBUG: #{msg}" if Launchy.debug?
end

.open(uri, options = {}) ⇒ Object

Convenience method to launch an item



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/launchy.rb', line 25

def open(uri, options = {} )
  begin
    extract_global_options( options )
    uri = Addressable::URI.parse(  uri )
    app = Launchy::Application.handling( uri )
    app.new.open( uri, options )
  rescue Exception => e
    msg = "Failure in opening #{uri} with options #{options.inspect}: #{e}"
    Launchy.log "#{self.name} : #{msg}"
    e.backtrace.each do |bt|
      Launchy.log bt
    end
    $stderr.puts msg
  end
end

.reset_global_optionsObject



41
42
43
44
45
46
47
# File 'lib/launchy.rb', line 41

def reset_global_options
  Launchy.debug       = false
  Launchy.application = nil
  Launchy.host_os     = nil
  Launchy.ruby_engine = nil
  Launchy.dry_run     = false
end

.ruby_engineObject



87
88
89
# File 'lib/launchy.rb', line 87

def ruby_engine
  @ruby_engine || ENV['LAUNCHY_RUBY_ENGINE']
end

.ruby_engine=(ruby_engine) ⇒ Object



83
84
85
# File 'lib/launchy.rb', line 83

def ruby_engine=( ruby_engine )
  @ruby_engine = ruby_engine
end