guard-go 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in guard-go.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Victor Castell
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,23 @@
1
+ # Guard::Go
2
+
3
+ Guard Go runs go programs and restart when file changes
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'guard-go'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install guard-go
18
+
19
+ ## Usage
20
+
21
+ $ guard init go
22
+
23
+ This will create your Guardfile. Edit it and configure your application file name.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/guard-go.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/guard/go/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Victor Castell"]
6
+ gem.email = ["victorcoder@gmail.com"]
7
+ gem.description = %q{Guard gem for Go}
8
+ gem.summary = %q{Guard gem for launching go files}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "guard-go"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Guard::GoVersion::VERSION
17
+
18
+ gem.add_dependency 'guard', '>= 1.0.0'
19
+ end
@@ -0,0 +1,52 @@
1
+ require 'fileutils'
2
+
3
+ module Guard
4
+ class GoRunner
5
+ MAX_WAIT_COUNT = 10
6
+
7
+ attr_reader :options, :pid
8
+
9
+ def initialize(file, options)
10
+ @file = file
11
+ @options = options
12
+ end
13
+
14
+ def start
15
+ run_go_command!
16
+ end
17
+
18
+ def stop
19
+ ps_go_pid.each do |pid|
20
+ system %{kill -KILL #{pid}}
21
+ end
22
+ while ps_go_pid.count > 0
23
+ wait sleep_time
24
+ end
25
+ end
26
+
27
+ def restart
28
+ stop
29
+ start
30
+ end
31
+
32
+ def build_go_command
33
+ %{cd #{Dir.pwd} && go run #{@file}}
34
+ end
35
+
36
+ def ps_go_pid
37
+ `ps aux | awk '/a.out/&&!/awk/{print $2;}'`.split("\n").map { |pid| pid.to_i }
38
+ end
39
+
40
+ def sleep_time
41
+ options[:timeout].to_f / MAX_WAIT_COUNT.to_f
42
+ end
43
+
44
+ private
45
+ def run_go_command!
46
+ @pid = fork do
47
+ exec build_go_command
48
+ end
49
+ @pid
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,6 @@
1
+ # Add files and commands to this file, like the example:
2
+ # watch(%r{file/path}) { `command(s)` }
3
+ #
4
+ guard 'go' do
5
+ watch('app.go')
6
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module GoVersion
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/guard/go.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+ require 'guard/watcher'
4
+ require 'guard/go/runner'
5
+
6
+ module Guard
7
+ class Go < ::Guard::Guard
8
+ attr_reader :options
9
+
10
+ def initialize(watchers = [], options = {})
11
+ super
12
+
13
+ go_file = watchers.first.pattern || 'app.go'
14
+
15
+ unless File.exists? go_file
16
+ raise "Go file #{go_file} not found"
17
+ end
18
+ @runner = ::Guard::GoRunner.new(go_file, options)
19
+ end
20
+
21
+ def start
22
+ UI.info "Starting Go..."
23
+ if pid = @runner.start
24
+ UI.info "Started Go app, pid #{pid}"
25
+ end
26
+ end
27
+
28
+ def run_on_change
29
+ UI.info "Restarting Go..."
30
+ if @runner.restart
31
+ UI.info "Go restarted, pid #{@runner.pid}"
32
+ else
33
+ UI.info "Go NOT restarted, check your log files."
34
+ end
35
+ end
36
+
37
+ def stop
38
+ @runner.stop
39
+ UI.info "Stopping Go..."
40
+ Notifier.notify("Until next time...", :title => "Go shutting down.", :image => :pending)
41
+ end
42
+ end
43
+ end
data/lib/guard-go.rb ADDED
@@ -0,0 +1 @@
1
+ require 'guard/go'
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-go
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Victor Castell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: guard
16
+ requirement: &70240600442320 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70240600442320
25
+ description: Guard gem for Go
26
+ email:
27
+ - victorcoder@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - guard-go.gemspec
38
+ - lib/guard-go.rb
39
+ - lib/guard/go.rb
40
+ - lib/guard/go/runner.rb
41
+ - lib/guard/go/templates/Guardfile
42
+ - lib/guard/go/version.rb
43
+ homepage: ''
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.11
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Guard gem for launching go files
67
+ test_files: []