guard-combustion 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 13d535c12e2065b16c6dd2c39d63912cd62b94e0
4
+ data.tar.gz: 9db93c30fd2be56cfff66abaf2a8a0fe188138af
5
+ SHA512:
6
+ metadata.gz: cbf395173ea18af253b85c2ef38100b0ab47477ba5ba83c909384dcbc706cdc90d8c7328bc60fed0e6202b9d53510dc5871f039ffb26b4673320ebc06fd602bf
7
+ data.tar.gz: 36810e84b4ab5c3a2063248bb8025ec01b0cceabf3c0e21e98c011b3f58ea194af8355389a2852ec8d718735c252e420ea614e7f1936d49f8d9adf2c43760dbe
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Ruben Caliandro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Readme.md ADDED
@@ -0,0 +1,33 @@
1
+ # Guard::Combustion
2
+
3
+ This guard allows you to easily develop Rails engines with [Combustion](https://github.com/pat/combustion) with no need to restart the dummy application after every change.
4
+
5
+
6
+ ## Install
7
+
8
+ Make sure you have [guard](http://github.com/guard/guard) installed and Combustion fully configured on your Rails engine.
9
+
10
+ Install the gem with:
11
+
12
+ gem install guard-combustion
13
+
14
+ Or add it to your Gemfile:
15
+
16
+ gem 'guard-combustion'
17
+
18
+ And then add a basic setup to your Guardfile:
19
+
20
+ guard init combustion
21
+
22
+
23
+ ## Integration with guard-rspec
24
+
25
+ If you are using guard-rspec, maybe you want to stop Combustion while running tests,
26
+ just to avoid conflicts with the instance of Combustion created by Rspec.
27
+
28
+ For doing that, you have to add theese lines into the `guard :rspec` block
29
+
30
+ callback(:run_all_begin) { CombustionHelper.stop_combustion }
31
+ callback(:run_on_modifications_begin) { CombustionHelper.stop_combustion }
32
+ callback(:run_all_end) { CombustionHelper.start_combustion }
33
+ callback(:run_on_modifications_end) { CombustionHelper.start_combustion }
@@ -0,0 +1,144 @@
1
+ #
2
+ # Questa classe contiene funzioni utili per la gestione automatica di combustion con guard
3
+ #
4
+ # Per configurare la porta utilizzata da combustion, inserire in un file ".guard_combustion_port" la porta desiderata (solo il numero).
5
+ # Se questo file non esiste, viene creato automaticamente al primo utilizzo di guard, utilizzando la porta di default.
6
+ #
7
+ # NB: .guard_combustion_port è gitignored.
8
+ #
9
+ class CombustionHelper
10
+
11
+ #
12
+ # La porta di default utilizzata da combustion.
13
+ # Questa porta viene utilizzata solo se non è già stata configurata in .guard_combustion_port
14
+ #
15
+ # NB: per modificare la porta che si vuole far utilizzare a combustion non modificare direttamente questa variabile.
16
+ # Leggere invece le istruzioni in cima alla classe
17
+ #
18
+ @@default_port = 9292
19
+ @@last_start = Time.now - 5
20
+ @@combustion_pid_file = "./tmp/.combustion_pid"
21
+ @@guard_combustion_port = ".guard_combustion_port"
22
+
23
+ #
24
+ # Definisce tutti i metodi come statici
25
+ #
26
+ class << self
27
+ #
28
+ # Avvia combustion
29
+ #
30
+ def start_combustion
31
+ if get_combustion_pid.nil?
32
+ puts "starting combustion..."
33
+ combustion_port = get_guard_combustion_port
34
+ `#{combustion_cmd(combustion_port)}`
35
+ sleep(1)
36
+ @@last_start = Time.now
37
+ pid = get_combustion_pid
38
+ if pid.nil?
39
+ puts "something went wrong, likely combustion were not started"
40
+ else
41
+ puts "\033[22;32mcombustion started and listening at port #{combustion_port} with pid #{pid}\x1b[0m"
42
+ end
43
+ else
44
+ puts "another instance of combustion is already running with pid #{pid}"
45
+ restart_combustion
46
+ end
47
+ end
48
+
49
+ #
50
+ # Uccide combustion
51
+ #
52
+ def stop_combustion
53
+ puts "stopping combustion..."
54
+ pid = get_combustion_pid
55
+ if pid.nil?
56
+ puts "no instances of combustion were found"
57
+ else
58
+ `kill -9 #{pid}`
59
+ puts "\033[22;31mcombustion stopped\x1b[0m"
60
+ delete_combustion_pid
61
+ end
62
+ end
63
+
64
+ #
65
+ # Riavvia combustion
66
+ #
67
+ def restart_combustion
68
+ if Time.now > @@last_start + 1 # Controlla che il server non sia stato già avviato meno di 1 secondo fa
69
+ puts "\033[01;33mrestarting combustion...\x1b[0m"
70
+ stop_combustion
71
+ start_combustion
72
+ end
73
+ end
74
+
75
+ private
76
+
77
+ #
78
+ # Scrive la porta di default che verrà utilizzata per combustion in un file .guard_combustion_port
79
+ #
80
+ def set_guard_combustion_port
81
+ file = File.open(@@guard_combustion_port, "w")
82
+ file.write(@@default_port.to_s)
83
+ file.close
84
+ @@default_port
85
+ end
86
+
87
+ #
88
+ # Legge la porta di default che viene utilizzata per combustion dal file .guard_combustion_port
89
+ # Se il file non esiste, lo crea e gli assegna la porta di default
90
+ #
91
+ def get_guard_combustion_port
92
+ begin
93
+ if File.exists? @@guard_combustion_port
94
+ file = File.open(@@guard_combustion_port, "r")
95
+ contents = file.read
96
+ combustion_port = Integer(contents.split("\n")[0])
97
+ file.close
98
+ combustion_port
99
+ else
100
+ set_guard_combustion_port
101
+ end
102
+ rescue ArgumentError => e
103
+ file.close
104
+ set_guard_combustion_port
105
+ end
106
+ end
107
+
108
+ #
109
+ # Legge il pid di combustion dal file .combustion_pid
110
+ #
111
+ def get_combustion_pid
112
+ begin
113
+ if File.exists? @@combustion_pid_file
114
+ file = File.open(@@combustion_pid_file, "r")
115
+ contents = file.read
116
+ combustion_pid = Integer(contents.split("\n")[0])
117
+ file.close
118
+ combustion_pid
119
+ else
120
+ nil
121
+ end
122
+ rescue ArgumentError => e
123
+ file.close
124
+ nil
125
+ end
126
+ end
127
+
128
+ #
129
+ # Elimina il file .combustion_pid
130
+ #
131
+ def delete_combustion_pid
132
+ if File.exists? @@combustion_pid_file
133
+ File.delete(@@combustion_pid_file)
134
+ end
135
+ end
136
+
137
+ #
138
+ # Restituisce su una stringa il comando shell utilizzato per avviare combustion
139
+ #
140
+ def combustion_cmd combustion_port
141
+ "rackup -p #{combustion_port} -D -P #{@@combustion_pid_file}"
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,6 @@
1
+ # Add files to watch, like the example:
2
+ # watch(%r{file/path})
3
+ #
4
+ guard :combustion do
5
+ watch(%r{^(app|config|lib|spec)/(.*)})
6
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module CombustionVersion
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+ require 'guard/combustion/version'
4
+ require 'guard/combustion/combustion_helper'
5
+
6
+ module Guard
7
+ class Combustion < Guard
8
+
9
+ def start
10
+ CombustionHelper.start_combustion
11
+ end
12
+
13
+ def stop
14
+ CombustionHelper.stop_combustion
15
+ end
16
+
17
+ def reload
18
+ CombustionHelper.restart_combustion
19
+ end
20
+
21
+ def run_all
22
+ reload
23
+ end
24
+
25
+ def run_on_change(paths)
26
+ reload
27
+ end
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-combustion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ruben Caliandro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: guard
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.0
27
+ description: |2
28
+ Guard::Combustion automatically restarts Combustion when watched files are
29
+ modified.
30
+ email: ruben.caliandro@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE
36
+ - Readme.md
37
+ - lib/guard/combustion.rb
38
+ - lib/guard/combustion/combustion_helper.rb
39
+ - lib/guard/combustion/templates/Guardfile
40
+ - lib/guard/combustion/version.rb
41
+ homepage: http://github.com/Chosko/guard-combustion
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.2.0
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Guard gem for running Combustion
65
+ test_files: []