guard-zeus_server 0.0.2

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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in guard-zeus-server.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Aaron Jensen
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,38 @@
1
+ # Guard::Zeus::Server
2
+
3
+ Starts/stops/restarts your rails server via zeus.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'guard-zeus-server'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install guard-zeus-server
18
+
19
+ ## Usage
20
+
21
+ Run:
22
+
23
+ $ guard init zeus_server
24
+
25
+ Modify the `Guardfile` to your heart's content.
26
+
27
+ Options:
28
+
29
+ * `:port` is the port number to pass to `zeus server`. Defaults to `3000`.
30
+ * `:command` is the zeus command to run. Defaults to `server`.
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'guard/zeus_server/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "guard-zeus_server"
8
+ gem.version = Guard::Zeus::Server::VERSION
9
+ gem.authors = ["Aaron Jensen"]
10
+ gem.email = ["aaronjensen@gmail.com"]
11
+ gem.description = %q{Guard for "zeus server"}
12
+ gem.summary = %q{Automatically starts/stops/restarts "zeus server" with guard.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'guard', '>= 1.4'
21
+
22
+ gem.add_development_dependency 'rspec'
23
+ gem.add_development_dependency 'fakefs'
24
+ end
@@ -0,0 +1,88 @@
1
+ require 'fileutils'
2
+
3
+ module Guard
4
+ class ZeusServer
5
+ class Runner
6
+ attr_accessor :options
7
+
8
+ def initialize(options)
9
+ @options = options
10
+ end
11
+
12
+ def start
13
+ delete_abandonded_pid_file
14
+ return true if has_pid?
15
+
16
+ zeus_options = [
17
+ '-d',
18
+ '-p', port,
19
+ '-P', pid_file,
20
+ ]
21
+
22
+ system "cd #{Dir.pwd}; zeus server #{zeus_options.join(' ')}"
23
+ wait_until { has_pid? }
24
+ end
25
+
26
+ def stop
27
+ kill if has_pid?
28
+ true
29
+ end
30
+
31
+ def restart
32
+ stop
33
+ start
34
+ end
35
+
36
+ private
37
+ def kill
38
+ pid = read_pid
39
+ system "kill -SIGINT #{pid}"
40
+
41
+ unless wait_until { !has_pid? }
42
+ system "kill -SIGKILL #{pid}"
43
+ delete_pid_file
44
+ end
45
+ end
46
+
47
+ def running?(pid)
48
+ system "kill 0 #{pid}"
49
+ end
50
+
51
+ def wait_until(&block)
52
+ thread = Thread.new do
53
+ until block.call
54
+ sleep 0.1
55
+ end
56
+ end
57
+ !!thread.join(10)
58
+ end
59
+
60
+ def delete_abandonded_pid_file
61
+ return unless has_pid?
62
+ return if system("kill -0 #{read_pid}")
63
+
64
+ delete_pid_file
65
+ end
66
+
67
+ def delete_pid_file
68
+ FileUtils.rm pid_file
69
+ end
70
+
71
+ def read_pid
72
+ has_pid? ? File.read(pid_file).to_i : nil
73
+ end
74
+
75
+ def pid_file
76
+ File.expand_path("tmp/pids/zeus_#{options.fetch(:command)}.pid")
77
+ end
78
+
79
+ def has_pid?
80
+ File.file?(pid_file)
81
+ end
82
+
83
+ def port
84
+ options.fetch(:port)
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,8 @@
1
+ guard 'zeus_server' do
2
+ watch('Gemfile')
3
+ watch('Gemfile.lock')
4
+ watch('config/application.rb')
5
+ watch('config/environment.rb')
6
+ watch(%r{^config/environments/.*\.rb$})
7
+ watch(%r{^config/initializers/.*\.rb$})
8
+ end
@@ -0,0 +1,7 @@
1
+ module Guard
2
+ module Zeus
3
+ module Server
4
+ VERSION = "0.0.2"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,72 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+ require 'guard/zeus_server/version'
4
+
5
+ module Guard
6
+ class ZeusServer < Guard
7
+ autoload :Runner, 'guard/zeus_server/runner'
8
+ attr_accessor :options, :runner
9
+
10
+ DEFAULT_OPTIONS = {
11
+ :port => 3000,
12
+ :command => "server"
13
+ }
14
+
15
+ # Initialize a Guard.
16
+ # @param [Array<Guard::Watcher>] watchers the Guard file watchers
17
+ # @param [Hash] options the custom Guard options
18
+ def initialize(watchers = [], options = {})
19
+ super
20
+ self.options = DEFAULT_OPTIONS.merge(options)
21
+ self.runner = Runner.new self.options
22
+ end
23
+
24
+ # Call once when Guard starts. Please override initialize method to init stuff.
25
+ # @raise [:task_has_failed] when start has failed
26
+ def start
27
+ UI.info "Guard::ZeusServer is starting \"zeus #{options[:command]}\" on port #{options[:port]}."
28
+ unless runner.start
29
+ UI.warning "Guard::ZeusServer failed to start \"zeus #{options[:command]}\"."
30
+ end
31
+ end
32
+
33
+ # Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
34
+ # @raise [:task_has_failed] when stop has failed
35
+ def stop
36
+ UI.info "Guard::ZeusServer is stopping \"zeus #{options[:command]}\" on port #{options[:port]}."
37
+ unless runner.stop
38
+ UI.warning "Guard::ZeusServer failed to stop \"zeus #{options[:command]}\"."
39
+ end
40
+ end
41
+
42
+ # Called when `reload|r|z + enter` is pressed.
43
+ # This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
44
+ # @raise [:task_has_failed] when reload has failed
45
+ def reload
46
+ UI.info "Guard::ZeusServer is restarting \"zeus #{options[:command]}\" on port #{options[:port]}."
47
+ unless runner.restart
48
+ UI.warning "Guard::ZeusServer failed to restart \"zeus #{options[:command]}\"."
49
+ end
50
+ end
51
+
52
+ # Called when just `enter` is pressed
53
+ # This method should be principally used for long action like running all specs/tests/...
54
+ # @raise [:task_has_failed] when run_all has failed
55
+ def run_all
56
+ end
57
+
58
+ # Called on file(s) modifications that the Guard watches.
59
+ # @param [Array<String>] paths the changes files or paths
60
+ # @raise [:task_has_failed] when run_on_change has failed
61
+ def run_on_changes(paths)
62
+ reload
63
+ end
64
+
65
+ # Called on file(s) deletions that the Guard watches.
66
+ # @param [Array<String>] paths the deleted files or paths
67
+ # @raise [:task_has_failed] when run_on_change has failed
68
+ def run_on_removals(paths)
69
+ reload
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+ require 'guard/zeus_server/runner'
3
+ require 'fakefs/spec_helpers'
4
+
5
+ describe Guard::ZeusServer::Runner do
6
+ include FakeFS::SpecHelpers
7
+ let(:options) { { :port => 3000, :command => "server" } }
8
+ let(:runner) { Guard::ZeusServer::Runner.new(options) }
9
+ let(:pid_file) { File.expand_path("tmp/pids/zeus_server.pid") }
10
+
11
+ before do
12
+ FileUtils.mkdir_p "/project"
13
+ Dir.chdir "/project"
14
+ runner.stub :system
15
+ end
16
+
17
+ describe "#start" do
18
+ before do
19
+ runner.stub(:wait_until) { true }
20
+ end
21
+ it "should start zeus server" do
22
+ runner.should_receive(:system).with("cd /project; zeus server -d -p 3000 -P #{pid_file}")
23
+
24
+ runner.start
25
+ end
26
+
27
+ it "should set the pid" do
28
+ command_should_include(" -P #{pid_file}")
29
+
30
+ runner.start
31
+ end
32
+
33
+ it "should be daemonized" do
34
+ command_should_include(" -d")
35
+
36
+ runner.start
37
+ end
38
+
39
+ it "should let you change the port" do
40
+ options[:port] = 1234
41
+ command_should_include(" -p 1234")
42
+
43
+ runner.start
44
+ end
45
+
46
+ it "should delete the pidfile if it's not running" do
47
+ create_pid_file(54444)
48
+ runner.stub(:system).with("kill -0 54444") { false }
49
+
50
+ runner.start
51
+ File.file?(pid_file).should_not be
52
+ end
53
+
54
+ it "should not start the server if it is already running" do
55
+ create_pid_file(54444)
56
+ runner.stub(:system).with("kill -0 54444") { true }
57
+ runner.should_not_receive(:system).with do |command|
58
+ command =~ /zeus/
59
+ end
60
+
61
+ runner.start
62
+ end
63
+ end
64
+
65
+ describe "#stop" do
66
+ it "should kill an existing pid" do
67
+ create_pid_file(54444)
68
+
69
+ runner.should_receive(:system).with("kill -SIGINT 54444") do
70
+ FileUtils.rm pid_file
71
+ end
72
+ runner.stub(:system).with("kill 0 54444") { false }
73
+
74
+ runner.stop
75
+ end
76
+ end
77
+
78
+ describe "#restart" do
79
+ it "should stop then start" do
80
+ runner.should_receive(:stop).ordered
81
+ runner.should_receive(:start).ordered
82
+
83
+ runner.restart
84
+ end
85
+ end
86
+
87
+ def command_should_include(part)
88
+ runner.should_receive(:system).with do |command|
89
+ command.should match /#{part}\b/
90
+ end
91
+ end
92
+
93
+ def create_pid_file(pid)
94
+ FileUtils.mkdir_p File.dirname(pid_file)
95
+ File.open(pid_file, 'w') { |file| file.print pid }
96
+ end
97
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+ require 'guard/zeus_server'
3
+
4
+ describe Guard::ZeusServer do
5
+ let(:options) { {} }
6
+ let(:watchers) { [] }
7
+ let(:runner) { stub }
8
+ let(:guard) { Guard::ZeusServer.new(watchers, options) }
9
+
10
+ before do
11
+ guard.runner = runner
12
+ end
13
+
14
+ it "should have default options" do
15
+ guard.options[:port].should == 3000
16
+ guard.options[:command].should == "server"
17
+ end
18
+
19
+ describe "#start" do
20
+ it "should start the runner" do
21
+ runner.should_receive(:start)
22
+
23
+ guard.start
24
+ end
25
+ end
26
+
27
+ describe "#stop" do
28
+ it "should stop the runner" do
29
+ runner.should_receive(:stop)
30
+
31
+ guard.stop
32
+ end
33
+ end
34
+
35
+ describe "#reload" do
36
+ it "should stop the runner" do
37
+ runner.should_receive(:restart)
38
+
39
+ guard.reload
40
+ end
41
+ end
42
+
43
+ describe "#run_all" do
44
+ it "should do nothing" do
45
+ guard.run_all
46
+ end
47
+ end
48
+
49
+ describe "#run_on_changes" do
50
+ it "should restart the runner" do
51
+ runner.should_receive(:restart)
52
+
53
+ guard.run_on_changes("foo.rb")
54
+ end
55
+ end
56
+
57
+ describe "#run_on_removals" do
58
+ it "should restart the runner" do
59
+ runner.should_receive(:restart)
60
+
61
+ guard.run_on_removals("foo.rb")
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-zeus_server
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aaron Jensen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: guard
16
+ prerelease: false
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '1.4'
22
+ none: false
23
+ type: :runtime
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ! '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '1.4'
29
+ none: false
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ prerelease: false
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ none: false
39
+ type: :development
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ none: false
46
+ - !ruby/object:Gem::Dependency
47
+ name: fakefs
48
+ prerelease: false
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ none: false
55
+ type: :development
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ none: false
62
+ description: Guard for "zeus server"
63
+ email:
64
+ - aaronjensen@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .travis.yml
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - guard-zeus_server.gemspec
76
+ - lib/guard/zeus_server.rb
77
+ - lib/guard/zeus_server/runner.rb
78
+ - lib/guard/zeus_server/templates/Guardfile
79
+ - lib/guard/zeus_server/version.rb
80
+ - spec/lib/guard/zeus_server/runner_spec.rb
81
+ - spec/lib/guard/zeus_server_spec.rb
82
+ - spec/spec_helper.rb
83
+ homepage: ''
84
+ licenses: []
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ none: false
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ none: false
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.24
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Automatically starts/stops/restarts "zeus server" with guard.
107
+ test_files:
108
+ - spec/lib/guard/zeus_server/runner_spec.rb
109
+ - spec/lib/guard/zeus_server_spec.rb
110
+ - spec/spec_helper.rb