waiting_on_rails 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,17 @@
1
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
2
+ this software and associated documentation files (the "Software"), to deal in
3
+ the Software without restriction, including without limitation the rights to
4
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
5
+ of the Software, and to permit persons to whom the Software is furnished to do
6
+ so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all
9
+ copies or substantial portions of the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ [![Build Status](https://travis-ci.org/AndrewRadev/waiting-on-rails.png)](https://travis-ci.org/AndrewRadev/waiting-on-rails)
2
+
3
+ Bored of waiting on `rails server` or `rake routes`? No more! This gem provides two commands, `waiting-on-rails` and `waiting-on-rake`. They are meant as replacements to `rails` and `rake`, respectively, so you can call them like this:
4
+
5
+ waiting-on-rails server
6
+ waiting-on-rake db:migrate
7
+
8
+ What's the difference? Aside from running the required task, they also play some relaxing elevator music, so you'll never get bored of waiting again. Problem solved!
9
+
10
+ ## Gotchas
11
+
12
+ Okay, so `waiting-on-rails` only plays music for the `server` task, not for the similarly long-loading `console` cousin, but I have no idea how to run the console in a child process and control its IO. Pull requests welcome. And `waiting-on-rake` only plays music for long-running tasks (see `slow_tasks` method in [this file](https://github.com/AndrewRadev/waiting-on-rails/blob/master/lib/waiting_on_rails/rake.rb)), but that's intentional.
13
+
14
+ Also, it only works for the following webservers:
15
+
16
+ - WEBrick
17
+ - Mongrel
18
+ - Thin
19
+
20
+ It should be possible to add support for more by adding to the `matches_server_start?` method in [this file](https://github.com/AndrewRadev/waiting-on-rails/blob/master/lib/waiting_on_rails/rails.rb). Again, pull requests welcome.
21
+
22
+ ## Installation and Usage Details
23
+
24
+ The first thing you need to do is install the gem (note the underscores):
25
+
26
+ gem install waiting_on_rails
27
+
28
+ The gem requires `mplayer` to play its music. On a Mac, you can install mplayer with homebrew:
29
+
30
+ brew install mplayer
31
+
32
+ On Linux, you should use your distribution's package manager. For Arch Linux, the command would be:
33
+
34
+ pacman -S mplayer
35
+
36
+ You could run `waiting-on-rails` without using `bundle exec` (unless it's run by a bundle-exec-ed script, like with a Procfile), but you probably won't be able to with `waiting-on-rake`. So if you're serious about battling boring loading times, you're going to have to add it to your Gemfile with a `:require => false`. If you just want a quick laugh, install the gem globally and start your project with `waiting-on-rails s`. Preferably in front of your unsuspecting coworkers. Amusement not guaranteed, but very likely.
37
+
38
+ ## TODO
39
+
40
+ - Implement `waiting-on-spork`?
41
+ - Implement continuing from a point. Could save a temporary file somewhere with the time at which the music was stopped.
42
+ - Implement simple configuration, controlling what song to play, or even something different to do (like show a notification). Warning: might make the project actually useful, consider carefully.
43
+
44
+ ## Music sources
45
+
46
+ Both music sources are CC-licensed and can be found at the following urls:
47
+
48
+ - Elevator music: http://www.jamendo.com/en/list/a98147/echoes-from-the-past
49
+ - Elevator ding: http://soundbible.com/1441-Elevator-Ding.html
@@ -0,0 +1,11 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $: << File.expand_path('../../lib', __FILE__)
4
+
5
+ require 'waiting_on_rails/player'
6
+ require 'waiting_on_rails/rails'
7
+
8
+ music = WaitingOnRails::Player.new('attempt_1.mp3')
9
+ ding = WaitingOnRails::Player.new('ding.wav')
10
+
11
+ WaitingOnRails::Rails.new(music, ding).run(ARGV)
@@ -0,0 +1,10 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $: << File.expand_path('../../lib', __FILE__)
4
+
5
+ require 'waiting_on_rails/rake'
6
+
7
+ music = WaitingOnRails::Player.new('attempt_1.mp3')
8
+ ding = WaitingOnRails::Player.new('ding.wav')
9
+
10
+ WaitingOnRails::Rake.new(music, ding).run(ARGV)
@@ -0,0 +1,28 @@
1
+ module WaitingOnRails
2
+ class Player
3
+ attr_reader :pid
4
+
5
+ def initialize(music_path)
6
+ @music_path = full_path(music_path)
7
+ end
8
+
9
+ def start
10
+ @pid = spawn("mplayer #{@music_path}", :out => '/dev/null', :err => '/dev/null')
11
+ end
12
+
13
+ def stop
14
+ return true if @pid.nil?
15
+ Process.kill(15, @pid)
16
+ Process.wait(@pid)
17
+ true
18
+ rescue Errno::ESRCH, Errno::ECHILD
19
+ false
20
+ end
21
+
22
+ private
23
+
24
+ def full_path(path)
25
+ File.expand_path("#{File.dirname(__FILE__)}/../../vendor/#{path}")
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,91 @@
1
+ require 'pty'
2
+ require 'waiting_on_rails/player'
3
+
4
+ module WaitingOnRails
5
+ class Exit < Exception; end
6
+
7
+ class Rails
8
+ def initialize(music_player, ding_player = nil)
9
+ @music_player = music_player
10
+ @ding_player = ding_player
11
+ end
12
+
13
+ def run(args)
14
+ if not should_play_music?(args)
15
+ exec_rails_command(args)
16
+ end
17
+
18
+ spawn_rails_subprocess(args) do |output, pid|
19
+ @music_player.start
20
+ handle_signals(pid, output)
21
+ main_loop(output)
22
+ end
23
+ rescue Exit
24
+ exit(1)
25
+ ensure
26
+ @music_player.stop
27
+ end
28
+
29
+ private
30
+
31
+ def spawn_rails_subprocess(args)
32
+ PTY.spawn('rails', *args) do |output, input, pid|
33
+ yield output, pid
34
+ end
35
+ end
36
+
37
+ def exec_rails_command(args)
38
+ exec 'rails', *args
39
+ end
40
+
41
+ def main_loop(io)
42
+ loop do
43
+ begin
44
+ line = io.readline
45
+ puts line
46
+ if matches_server_start?(line)
47
+ @music_player.stop
48
+ sleep 0.5
49
+ @ding_player.start if @ding_player
50
+ end
51
+ rescue EOFError
52
+ break
53
+ rescue Errno::EIO
54
+ raise Exit
55
+ end
56
+ end
57
+ end
58
+
59
+ def handle_signals(pid, output)
60
+ %w(TERM INT).each do |signal|
61
+ Signal.trap(signal) do
62
+ Process.kill(signal, pid)
63
+
64
+ loop do
65
+ begin
66
+ puts output.readline
67
+ rescue EOFError
68
+ break
69
+ end
70
+ end
71
+
72
+ raise Exit
73
+ end
74
+ end
75
+ end
76
+
77
+ def should_play_music?(args)
78
+ File.exists?('script/rails') and args.find { |arg| ['server', 's'].include? arg }
79
+ end
80
+
81
+ def matches_server_start?(string)
82
+ patterns = [
83
+ 'WEBrick::HTTPServer#start', # WEBrick
84
+ 'Listening on', # Thin
85
+ 'Ctrl-C to shutdown', # Mongrel
86
+ ]
87
+
88
+ patterns.any? { |p| string.include?(p) }
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,70 @@
1
+ require 'waiting_on_rails/player'
2
+
3
+ module WaitingOnRails
4
+ class Rake
5
+ def initialize(music_player, ding_player = nil)
6
+ @music_player = music_player
7
+ @ding_player = ding_player
8
+ end
9
+
10
+ def run(args)
11
+ if given_tasks_are_slow?(args)
12
+ @music_player.start
13
+ Process.wait(spawn_rake_subprocess(args))
14
+ else
15
+ exec_rake_command(args)
16
+ end
17
+ @music_player.stop
18
+ sleep 0.5
19
+ @ding_player.start if @ding_player
20
+ ensure
21
+ @music_player.stop
22
+ end
23
+
24
+ private
25
+
26
+ def given_tasks_are_slow?(args)
27
+ args.any? { |task| slow_tasks.include?(task) }
28
+ end
29
+
30
+ def slow_tasks
31
+ [
32
+ 'db:create',
33
+ 'db:drop',
34
+ 'db:fixtures:load',
35
+ 'db:migrate',
36
+ 'db:migrate:status',
37
+ 'db:rollback',
38
+ 'db:schema:dump',
39
+ 'db:schema:load',
40
+ 'db:seed',
41
+ 'db:setup',
42
+ 'db:structure:dump',
43
+ 'db:version',
44
+ 'routes',
45
+ 'spec',
46
+ 'spec:controllers',
47
+ 'spec:helpers',
48
+ 'spec:lib',
49
+ 'spec:mailers',
50
+ 'spec:models',
51
+ 'spec:rcov',
52
+ 'spec:requests',
53
+ 'spec:routing',
54
+ 'spec:views',
55
+ 'stats',
56
+ 'test',
57
+ 'test:recent',
58
+ 'test:uncommitted',
59
+ ]
60
+ end
61
+
62
+ def exec_rake_command(args)
63
+ exec 'rake', *args
64
+ end
65
+
66
+ def spawn_rake_subprocess(args)
67
+ spawn 'rake', *args
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,3 @@
1
+ module WaitingOnRails
2
+ VERSION = '0.0.1'
3
+ end
File without changes
Binary file
Binary file
data/vendor/ding.wav ADDED
Binary file
data/vendor/test.mp3 ADDED
Binary file
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: waiting_on_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Radev
9
+ - Joan Karadimov
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-12-03 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 2.0.0
31
+ - !ruby/object:Gem::Dependency
32
+ name: rake
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: ! " Bored of waiting on \"rails server\"? No more! This gem plays
48
+ some nice\n elevator music when you run `waiting-on-rails server` and stops it
49
+ when the\n server is ready.\n"
50
+ email:
51
+ - andrey.radev@gmail.com
52
+ executables:
53
+ - waiting-on-rails
54
+ - waiting-on-rake
55
+ extensions: []
56
+ extra_rdoc_files: []
57
+ files:
58
+ - lib/waiting_on_rails/player.rb
59
+ - lib/waiting_on_rails/rake.rb
60
+ - lib/waiting_on_rails/rails.rb
61
+ - lib/waiting_on_rails/version.rb
62
+ - lib/waiting_on_rails.rb
63
+ - bin/waiting-on-rake
64
+ - bin/waiting-on-rails
65
+ - vendor/attempt_1.mp3
66
+ - vendor/attempt_2.mp3
67
+ - vendor/test.mp3
68
+ - vendor/ding.wav
69
+ - LICENSE
70
+ - README.md
71
+ homepage: http://github.com/AndrewRadev/waiting_on_rails
72
+ licenses: []
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ segments:
84
+ - 0
85
+ hash: -1546165163177782417
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: 1.3.6
92
+ requirements: []
93
+ rubyforge_project: waiting_on_rails
94
+ rubygems_version: 1.8.24
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Plays elevator music until `rails server` boots
98
+ test_files: []