openwhenready 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +1 -0
- data/bin/openwhenready +5 -0
- data/lib/openwhenready/version.rb +3 -0
- data/lib/openwhenready.rb +58 -0
- data/openwhenready.gemspec +24 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1218827e9185f351b6fb3faa39ee724ef40ace4f
|
4
|
+
data.tar.gz: b9bcb998524fe84d6fe673752421117ecd351910
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1d345a0a44b27e933f1b97e1dbe66b5d03f64bd7c643bcd5f0d5f0b2ae1e3abf1170a34dc555efb60213f8489c7c512fe9012b9a43cf8e0ee71257741cc34f92
|
7
|
+
data.tar.gz: d3f2dd8fa12437e947f82777fb59d86c3a1915366f3f77a4c02e23ca036f8a24f0fcd1c7b421c1af4f7a920f63e388235c869d5d2c5673c31a2fb5e7050fce58
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Andrew Fecheyr
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Openwhenready
|
2
|
+
|
3
|
+
Uses Launchy to open the browser to a specific URL whenever the URL is
|
4
|
+
ready to accept tcp connections. Useful when waiting for a local
|
5
|
+
webserver to finish loading.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'openwhenready'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install openwhenready
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
This gem comes with a binary. Simply run it in Terminal. The command
|
24
|
+
takes one or more URL arguments `openwhenready localhost:3000`.
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/openwhenready
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require "openwhenready/version"
|
2
|
+
require "launchy"
|
3
|
+
require "uri"
|
4
|
+
require "Socket"
|
5
|
+
require "Resolv"
|
6
|
+
|
7
|
+
module Openwhenready
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
def open(url)
|
12
|
+
url = normalize_url(url)
|
13
|
+
uri = URI(url)
|
14
|
+
ip, port = Resolv.getaddress(uri.host), uri.port
|
15
|
+
puts " waiting for #{url} to accept connections "
|
16
|
+
sleep 1 until port_open?(ip, port)
|
17
|
+
puts " opening #{url} in your browser "
|
18
|
+
Launchy.open(url)
|
19
|
+
end
|
20
|
+
|
21
|
+
def port_open?(ip, port)
|
22
|
+
# From http://stackoverflow.com/questions/3464551/shortening-socket-timeout-using-timeouttimeoutn-does-not-seem-to-work-for-me/3473208#3473208
|
23
|
+
socket_family = ip.include?(":") ? Socket::AF_INET6 : Socket::AF_INET
|
24
|
+
s = Socket.new(socket_family, Socket::SOCK_STREAM, 0)
|
25
|
+
sa = Socket.sockaddr_in(port, ip)
|
26
|
+
|
27
|
+
begin
|
28
|
+
s.connect_nonblock(sa)
|
29
|
+
rescue Errno::EINPROGRESS
|
30
|
+
if IO.select(nil, [s], nil, 1)
|
31
|
+
begin
|
32
|
+
s.connect_nonblock(sa)
|
33
|
+
rescue Errno::EISCONN
|
34
|
+
return true
|
35
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
|
44
|
+
def normalize_url(url)
|
45
|
+
# On OS X localhost gets resolved to an ipv6 address, but most
|
46
|
+
# webservers only listen to ipv4, so let's hardcode ipv4 for
|
47
|
+
# localhost
|
48
|
+
url = url.gsub("localhost", "127.0.0.1")
|
49
|
+
if url =~ /^[^:]+:\/\//
|
50
|
+
url
|
51
|
+
else
|
52
|
+
"http://#{url}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'openwhenready/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "openwhenready"
|
8
|
+
spec.version = Openwhenready::VERSION
|
9
|
+
spec.authors = ["Andrew Fecheyr"]
|
10
|
+
spec.email = ["andrew@bedesign.be"]
|
11
|
+
spec.description = %q{Open browser when URL is ready}
|
12
|
+
spec.summary = %q{Uses launchy to open a given URL whenever that URL is ready to accept incoming connections}
|
13
|
+
spec.homepage = "https://github.com/andruby/openwhenready"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "launchy"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openwhenready
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Fecheyr
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: launchy
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Open browser when URL is ready
|
56
|
+
email:
|
57
|
+
- andrew@bedesign.be
|
58
|
+
executables:
|
59
|
+
- openwhenready
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/openwhenready
|
69
|
+
- lib/openwhenready.rb
|
70
|
+
- lib/openwhenready/version.rb
|
71
|
+
- openwhenready.gemspec
|
72
|
+
homepage: https://github.com/andruby/openwhenready
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.0.3
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Uses launchy to open a given URL whenever that URL is ready to accept incoming
|
96
|
+
connections
|
97
|
+
test_files: []
|