guard-foreman 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8122ce0888dccef83983172378b2ec71791c0157
4
+ data.tar.gz: 23c67c7a07b7d2d13a3d2c100102ccb781edd0b0
5
+ SHA512:
6
+ metadata.gz: f6fb2293540ace3c8b172def3f010c16926187b63a479319b22aeeb6c730015a3bea2514169b67a662c5c3d71bdcb063873972aafa33c731cf245d216d2dd702
7
+ data.tar.gz: 4634fcfe87ec1aafb88d00ac988f167426ec6450a7cac28673a9fbe7226f535bfdbc738fb0b6553e6eadb59e9de889338bc1fb0f70eae4601feaa7379a39dafa
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ coverage/*
6
+ .ruby-version
7
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Dependencies
4
+ gemspec
5
+
6
+ gem 'rake'
7
+ gem 'minitest'
8
+ #gem 'coveralls', require: false
9
+
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Jonathan Arnett
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,77 @@
1
+ # Guard::Foreman
2
+
3
+ `Guard::Foreman` automatically restarts Foreman using [Guard] [gu].
4
+
5
+ [gu]: https://github.com/guard/guard
6
+
7
+
8
+ ## Installation
9
+
10
+ **NOTE**: Guard::Foreman is not yet finished! In fact, it's hardly begun. I'll
11
+ update here when I have finished it.
12
+
13
+ <!--Using Rubygems:-->
14
+
15
+ <!-- $ gem install guard-foreman -->
16
+
17
+ <!--Using Bundler, add this to your `Gemfile`, preferably in the `development` group:-->
18
+
19
+ ```ruby
20
+ group :development
21
+ gem 'guard-foreman'
22
+ end
23
+ ```
24
+
25
+ Add a sample Guard definition to your `Guardfile`:
26
+
27
+ $ guard init foreman
28
+
29
+
30
+ ## Guard General Usage
31
+
32
+ Please read the [guard usage doc] [gd] in order to find out more about Guard and
33
+ how to use Guards. There is also [a Railscast about Guard] [gc], created by Ryan
34
+ Bates.
35
+
36
+
37
+ [gd]: https://github.com/guard/guard/blob/master/README.md
38
+ [gc]: http://railscasts.com/episodes/264-guard
39
+
40
+ It is recommended that you also install the [ruby-gntp] [gntp] on Mac OS X,
41
+ [libnotify] [ln] on Linux, FreeBSD or Solaris or [rb-notifu] [notifu] in order
42
+ to have graphical notifications.
43
+
44
+ [gntp]: https://rubygems.org/gems/ruby_gntp
45
+ [ln]: https://rubygems.org/gems/libnotify
46
+ [notifu]: https://rubygems.org/gems/rb-notifu
47
+
48
+
49
+ ## Guardfile for guard-foreman
50
+
51
+ ```ruby
52
+ guard :foreman, profile: 'Profile.dev'
53
+ ```
54
+
55
+ Available options (Note: mostly stolen directly from the [Foreman documentation]
56
+ [fd]):
57
+
58
+ [fd]: http://ddollar.github.io/foreman/
59
+
60
+ * `:log_file` Specify a location to pipe the Foreman logs into. Defaults to
61
+ `log/foreman.log`
62
+ * `:concurrency` Specify the number of each process to run. This should be
63
+ passed in the format `process=num,process=num`
64
+ * `:env` Specify one or more .env files to load
65
+ * `:procfile` Specify an alternate Procfile to load
66
+ * `:port` Specify which port to use as the base for this application. Should be
67
+ a multiple of 1000.
68
+ * `:root` Specify an alternate application root. This defaults to the directory
69
+ containing the Procfile.
70
+
71
+ NOTE: The parent project of Guard::Foreman, [Guard::Unicorn] [gdu], has a
72
+ `:bundler` option available for using `bundle exec`. I have removed this bit of
73
+ functionality as the [Foreman Github page] [fgp] asks users to *not* put
74
+ Foreman in their Gemfiles.
75
+
76
+ [gdu]: https://github.com/andreimaxim/guard-unicorn
77
+ [fgp]: https://github.com/ddollar/foreman
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "guard-foreman"
6
+ s.version = "0.0.1"
7
+ s.authors = ["Andrei Maxim", "Jonathan Arnett"]
8
+ s.licenses = ['MIT']
9
+ s.email = ["jonarnett90@gmail.com"]
10
+ s.homepage = "https://github.com/J3RN/guard-foreman"
11
+ s.summary = "Guard for Foreman"
12
+ s.description = "Guard plug-in that allows you to restart Foreman"
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_dependency 'guard', '~> 2.6'
20
+ end
@@ -0,0 +1,105 @@
1
+ require 'guard'
2
+ require 'guard/plugin'
3
+
4
+ module Guard
5
+ class Foreman < Plugin
6
+
7
+ # Default log location (Rails in mind)
8
+ DEFAULT_LOG_LOCATION = "log/foreman.log"
9
+
10
+ # Initialize a Guard.
11
+ # @param [Array<Guard::Watcher>] watchers the Guard file watchers
12
+ # @param [Hash] options the custom Guard options
13
+ def initialize(options = {})
14
+ @log_file = options.fetch(:log_file, DEFAULT_LOG_LOCATION)
15
+ @concurrency = options[:concurrency]
16
+ @env = options[:env]
17
+ @procfile = options[:procfile]
18
+ @port = options[:port]
19
+ @root = options[:root]
20
+
21
+ super
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
+ # Stop if running
28
+ stop if @pid
29
+
30
+ cmd = []
31
+ cmd << "foreman start"
32
+ cmd << "-c #{@concurrency}" if @concurrency
33
+ cmd << "-e #{@env}" if @env
34
+ cmd << "-f #{@procfile}" if @procfile
35
+ cmd << "-p #{@port}" if @port
36
+ cmd << "-d #{@root}" if @root
37
+ cmd << "> #{@log_file}"
38
+
39
+
40
+ @pid = ::Process.fork do
41
+ system "#{cmd.join " "}"
42
+ end
43
+
44
+ info "Foreman started."
45
+ end
46
+
47
+ # Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
48
+ # @raise [:task_has_failed] when stop has failed
49
+ def stop
50
+ begin
51
+ ::Process.kill("QUIT", @pid) if ::Process.getpgid(@pid)
52
+
53
+ # foreman won't always shut down right away, so we're waiting for
54
+ # the getpgid method to raise an Errno::ESRCH that will tell us
55
+ # the process is not longer active.
56
+ sleep 1 while ::Process.getpgid(@pid)
57
+ info "Foreman stopped."
58
+ rescue Errno::ESRCH
59
+ # Don't do anything, the process does not exist
60
+ end
61
+ end
62
+
63
+ # Called when `reload|r|z + enter` is pressed.
64
+ # This method should be mainly used for "reload" (really!) actions like
65
+ # reloading passenger/spork/bundler/...
66
+ # @raise [:task_has_failed] when reload has failed
67
+ def reload
68
+ UI.info "Restarting Foreman..."
69
+ stop
70
+ start
71
+ end
72
+
73
+ # Called when just `enter` is pressed
74
+ # This method should be principally used for long action like running all specs/tests/...
75
+ # @raise [:task_has_failed] when run_all has failed
76
+ def run_all
77
+ start
78
+ end
79
+
80
+ # Called on file(s) modifications that the Guard watches.
81
+ # @param [Array<String>] paths the changes files or paths
82
+ # @raise [:task_has_failed] when run_on_change has failed
83
+ def run_on_changes(paths)
84
+ reload
85
+ end
86
+
87
+ def run_on_additions(paths)
88
+ reload
89
+ end
90
+
91
+ def run_on_modifications(paths)
92
+ reload
93
+ end
94
+
95
+ def run_on_removals(paths)
96
+ reload
97
+ end
98
+
99
+ private
100
+
101
+ def info(msg)
102
+ UI.info(msg)
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,15 @@
1
+ # Usage:
2
+ # guard :foreman, <options hash>
3
+ #
4
+ # Possible options:
5
+ # * :concurreny - how many of each type of process you would like to run (default is, sensibly, one of each)
6
+ # * :env - one or more .env files to load
7
+ # * :procfile - an alternate Procfile to use (default is Procfile)
8
+ # * :port - an alternate port to use (default is 5000)
9
+ # * :root - an alternate application root
10
+ guard :foreman, procfile: 'Procfile.dev' do
11
+ # Rails example - Watch controllers, models, helpers, lib, and config files
12
+ watch( /^app\/(controllers|models|helpers)\/.+\.rb$/ )
13
+ watch( /^lib\/.+\.rb$/ )
14
+ watch( /^config\/*/ )
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'bundler'
2
+
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+
11
+ require 'minitest/autorun'
12
+ #require 'coveralls'
13
+ #Coveralls.wear!
14
+
15
+ require 'guard/foreman'
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-foreman
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrei Maxim
8
+ - Jonathan Arnett
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-08-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: guard
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '2.6'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '2.6'
28
+ description: Guard plug-in that allows you to restart Foreman
29
+ email:
30
+ - jonarnett90@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - Gemfile
37
+ - LICENSE
38
+ - README.md
39
+ - guard-foreman.gemspec
40
+ - lib/guard/foreman.rb
41
+ - lib/guard/foreman/templates/Guardfile
42
+ - test/test_helper.rb
43
+ homepage: https://github.com/J3RN/guard-foreman
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.4.1
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Guard for Foreman
67
+ test_files:
68
+ - test/test_helper.rb
69
+ has_rdoc: