• Stars
    star
    775
  • Rank 58,632 (Top 2 %)
  • Language
    Ruby
  • License
    ISC License
  • Created over 16 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A helper for launching cross-platform applications in a fire and forget manner.

launchy

Build Status

DESCRIPTION

Launchy is helper class for launching cross-platform applications in a fire and forget manner.

There are application concepts (browser, email client, etc) that are common across all platforms, and they may be launched differently on each platform. Launchy is here to make a common approach to launching external applications from within ruby programs.

FEATURES

Currently only launching a browser is supported.

SYNOPSIS

You can use launchy on the commandline, within the Capybara and Rspec-rails testing environment, or via its API.

Commandline

% launchy https://www.ruby-lang.org/

There are additional command line options, use launchy --help to see them.

Using the BROWSER environment variable

Launchy has a predefined set of common browsers on each platform that it attempts to use, and of course it is not exhaustive. As a fallback you can make use of the somewhat standard BROWSER environment variable.

BROWSER works in a similar same way to PATH. It is a colon (:) separated list of commands to try. You can also put in a %s in the command and the URL you are attempting to open will be substituted there.

As an example if you set BROWSER=/usr/local/bin/firefox-bin -new-tab '%s':/usr/local/bin/google-chrome-stable and you call Launchy.open("https://www.ruby-lang.org/") then Launchy will try, in order:

  • /usr/local/bin/firefox-bin -new-tab 'https://www.ruby-lang.org'
  • /usr/local/bin/google-chrome-stable https://www.ruby-lang.org

Additional links on the use of BROWSER as an environment variable.

Capybara Testing

First, install Capybara and Rspec for Rails. Capybara provides the following method:

save_and_open_page

When inserted into your code at the place where you would like to open your program, and when rspec is run, Capybara displays this message:

Page saved to /home/code/my_app_name/tmp/capybara/capybara-current-date-and-time.html with save_and_open_page.
Please install the launchy gem to open page automatically.

With Launchy installed, when rspec is run again, it will launch an unstyled instance of the specific page. It can be especially useful when debugging errors in integration tests. For example:

context "signin" do
  it "lets a user sign in" do
    visit root_path
    click_link signin_path
    save_and_open_page
    page.should have_content "Enter your login information"
  end
end

Public API

In the vein of Semantic Versioning, this is the sole supported public API.

Launchy.open( uri, options = {} ) { |exception| }

At the moment, the only available 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

If Launchy.open is invoked with a block, then no exception will be thrown, and the block will be called with the parameters passed to #open along with the exception that was raised.

An example of using the public API:

Launchy.open( "https://www.ruby-lang.org" )

An example of using the public API and using the error block:

uri = "https://www.ruby-lang.org"
Launchy.open( uri ) do |exception|
  puts "Attempted to open #{uri} and failed because #{exception}"
end

UPGRADING from versions before 2.0.0

The previously published version of Launchy before the 2.0.0 series was 0.4.0. There have been so many changes, and a mistaken tag at 1.0.0, that I have decided to bump all the way to 2.x.y.

I have attempted to keep backward compatibility with the previous examples. The previous API examples of:

Launchy::Browser.run("https://www.ruby-lang.org/")

and

Launchy::Browser.new.visit("https://www.ruby-lang.org/")

will still work, and you will get a deprecation notice, along with the line of code you should probably update. For example, this is what would print out in the github gem if it was updated to use 2.0.x but not use the supported API.

% gh home
WARNING: You made a call to a deprecated Launchy API. This call should be changed to 'Launchy.open( uri )'
WARNING: I think I was able to find the location that needs to be fixed. Please go look at:
WARNING:
WARNING: /Users/jeremy/.rvm/gems/ruby-1.8.7-p334/gems/github-0.6.2/lib/commands/helpers.rb:275:in `open'
WARNING: helper :open do |url|
WARNING:   has_launchy? proc {
WARNING:     Launchy::Browser.new.visit url
WARNING:   }
WARNING: end
WARNING:
WARNING: If this is not the case, please file a bug. Please file a bug at https://github.com/copiousfreetime/launchy/issues/new

These deprecation notices will go away with version 3.0 and the only available API will be the documented one.

ISC LICENSE

https://opensource.org/licenses/isc-license.txt

Copyright (c) 2007-2020 Jeremy Hinegardner

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

More Repositories

1

hitimes

a fast, high resolution timer library for recording performance metrics
Ruby
144
star
2

stickler

a tool to organize and maintain an internal gem distribution server
Ruby
143
star
3

amalgalite

SQLite database engine embedded in a ruby extension.
C
95
star
4

crate

(No longer in development) Tool for building and packaging standalone statically compiled ruby appliations
Ruby
92
star
5

heel

Heel is a small static web server for use when you need a quick web server for a directory.
Ruby
68
star
6

tyrantmanager

ARCHIVED - A command line tool for managing Tokyo Tyrant instances
Ruby
34
star
7

qup

Qup is a generalized Ruby API for Message Queue and Publish/Subscribe messaging patterns.
Ruby
31
star
8

torid

Temporally Ordered IDs. Generate universally unique identifiers (UUID) that sort lexically in time order.
Ruby
27
star
9

mp4parser

This is an old fork of the pre-github-migration mp4parser from google code. You really should be looking at https://github.com/sannies/mp4parser instead.
Java
22
star
10

http-parser.rb

A ruby gem that embedds ry/http-parser in it as an extension
C
15
star
11

keybox

secure password storage
Ruby
13
star
12

deprecatable

Deprecatable is a library to help you, as a developer, deprecate your API and be proactive about helping people who use your library find where they need to update.
Ruby
13
star
13

htauth

HTAuth is a pure ruby replacement for the Apache support programs 'htdigest' and 'htpasswd'
Ruby
11
star
14

ashbe

Asbhe is a Ruby wrapper around the HBase java client library. It aims to make accessing HBase a more Ruby-esque experience.
Ruby
11
star
15

tokyo-tools

Ad-hoc tools for working with tokyo cabinet databases
C
10
star
16

kjess

(inactive since kestrel itself is now inactive) KJess is a Ruby Kestrel client implementing Kestrel's Memcache style protocol
Ruby
9
star
17

libsql-ruby

libsql database engine embedded in a ruby extension.
C
8
star
18

halog

A log parser and reporter for haproxy logs
Ruby
7
star
19

stunnel

stunnel with x-forwarded-for patch and x-ssl-protocol patch
C
7
star
20

gemology

Excavating Ruby's gems, what do we find, what do we learn.
Ruby
6
star
21

bridgetown_reveal

A reveal.js plugin for the bridgetown static site generator
Ruby
6
star
22

rabal

Ruby Architecture for Building Applications and Libraries
Ruby
5
star
23

activerecord-amalgalite-adapter

The ActiveRecord Adapter for the Amalgalite database
Ruby
4
star
24

ghent

GitHub EveNT - for lack of a better acronym. An experiment in processing GitHub Events.
Ruby
3
star
25

ruby-libtommath

[Archived] a ruby extension containing the libtommath multiple-precision integer library
C
3
star
26

snipe

A system for scraping twitter content based upon the gnip notification feed
Ruby
3
star
27

plain-old-tokyo-storage-presentation

Plain Old Tokyo Storage talk given at Red Dirt Ruby Conference - 2010
3
star
28

readorder

Readorder orders a list of files into a more effective read order.
Ruby
3
star
29

fixme

A Starting Point.
Ruby
2
star
30

flat_kit

A library and commandline program for reading, writing, indexing, sorting, and merging CSV, TSV, JSON and other flat-file formats.
Ruby
2
star
31

libsimple_metrics

A very simple C library for capturing metrics
2
star
32

billys_billing

Ruby client for the v2 version of Billy's Billing
Ruby
1
star
33

thin_search

The thinnest full text search you'll find.
Ruby
1
star
34

docker-base-alpine-s6-overlay

A minimal alpine linux docker container using s6-overlay based upon alpine packages
Dockerfile
1
star
35

libsql-client-ruby

LibsqlClient is the Ruby library to the libSQL sqld server (including Turso).
Ruby
1
star
36

tbar

Playing with Accounting
Ruby
1
star