garlando 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/lib/garlando.rb +47 -11
- data/lib/garlando/version.rb +1 -1
- data/lib/guard/garlando.rb +1 -1
- data/spec/garlando_spec.rb +30 -24
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7df483ab31891c11e362aafbfb137628e70d8de
|
4
|
+
data.tar.gz: 3f52745f445511cd001c4833c3cbbe9fa19a8538
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 084b5d5d080d188d4fc1d5965f5a3a501e67d2598846db7c7785225f2404583256d54266c15b79ba116ac73b9a29f16702fd66a1383087bfa2630446a65d6224
|
7
|
+
data.tar.gz: 3632eb33e871dfb109035f7640e1dbffabbd805006cf662c326e7170c38ea11965218b9792c2700c8ae2c26effd920530dd462bd916f588072128340a60e292a
|
data/Gemfile
CHANGED
data/lib/garlando.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'garlando/version'
|
2
2
|
require 'optparse'
|
3
3
|
require 'timeout'
|
4
|
+
require 'net/http'
|
4
5
|
|
5
6
|
module Garlando
|
6
7
|
class Server
|
7
|
-
COMMANDS = %i
|
8
|
+
COMMANDS = %i(start restart stop status)
|
8
9
|
OPTIONS = {
|
9
10
|
env: 'development',
|
10
11
|
host: '0.0.0.0',
|
@@ -12,7 +13,6 @@ module Garlando
|
|
12
13
|
pid: 'tmp/pids/garlando.pid',
|
13
14
|
port: 65501,
|
14
15
|
pwd: Dir.pwd,
|
15
|
-
server: 'thin',
|
16
16
|
}
|
17
17
|
|
18
18
|
def initialize(options={})
|
@@ -26,17 +26,14 @@ module Garlando
|
|
26
26
|
|
27
27
|
def start
|
28
28
|
abort 'server is already running?' if running?
|
29
|
-
abort "File could not found (#{env_path})" unless File.
|
29
|
+
abort "File could not found (#{env_path})" unless File.exist?(env_path)
|
30
30
|
|
31
31
|
Process.daemon nochdir = true
|
32
32
|
|
33
33
|
File.write pid_path, Process.pid.to_s
|
34
34
|
at_exit { File.unlink pid_path }
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
ENV['RACK_ENV'] = @options[:env]
|
39
|
-
require env_path
|
36
|
+
prepare
|
40
37
|
|
41
38
|
server.run application, Host: @options[:host], Port: @options[:port]
|
42
39
|
end
|
@@ -90,21 +87,61 @@ module Garlando
|
|
90
87
|
end
|
91
88
|
|
92
89
|
def reopen
|
93
|
-
file = File.open log_path, '
|
90
|
+
file = File.open log_path, 'a'
|
94
91
|
[STDOUT, STDERR].each { |e| e.reopen file }
|
95
92
|
end
|
96
93
|
|
97
94
|
def server
|
98
|
-
Rack::Handler.
|
95
|
+
Rack::Handler.default
|
99
96
|
end
|
100
97
|
|
101
98
|
def application
|
102
|
-
Rack::URLMap.new
|
99
|
+
Rack::Logger.new(Rack::CommonLogger.new(Rack::URLMap.new(rails.config.assets[:prefix] => rails.assets)))
|
103
100
|
end
|
104
101
|
|
105
102
|
def rails
|
106
103
|
Rails.application
|
107
104
|
end
|
105
|
+
|
106
|
+
def logger
|
107
|
+
Logger.new log_path
|
108
|
+
end
|
109
|
+
|
110
|
+
def relogging
|
111
|
+
rails.assets.logger = logger
|
112
|
+
end
|
113
|
+
|
114
|
+
def spinup
|
115
|
+
check = lambda do |path|
|
116
|
+
begin
|
117
|
+
Net::HTTP.start(@options[:host], @options[:port]) do |http|
|
118
|
+
http.open_timeout = http.read_timeout = nil
|
119
|
+
http.get path
|
120
|
+
throw :finish
|
121
|
+
end
|
122
|
+
rescue Errno::ECONNREFUSED
|
123
|
+
end
|
124
|
+
end
|
125
|
+
[
|
126
|
+
"#{rails.config.assets[:prefix]}/application.js",
|
127
|
+
"#{rails.config.assets[:prefix]}/application.css",
|
128
|
+
].each do |_path|
|
129
|
+
Thread.new(_path) do |path|
|
130
|
+
catch(:finish) { loop { check.call path } }
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def prepare
|
136
|
+
reopen
|
137
|
+
|
138
|
+
ENV['RACK_ENV'] = @options[:env]
|
139
|
+
require env_path
|
140
|
+
|
141
|
+
relogging
|
142
|
+
|
143
|
+
spinup
|
144
|
+
end
|
108
145
|
end
|
109
146
|
|
110
147
|
class CLI
|
@@ -127,7 +164,6 @@ module Garlando
|
|
127
164
|
options = Server::OPTIONS.dup
|
128
165
|
|
129
166
|
opt = OptionParser.new
|
130
|
-
opt.on('-s', '--server SERVER') { |v| options[:server] = v }
|
131
167
|
opt.on('-o', '--host HOST') { |v| options[:host] = v }
|
132
168
|
opt.on('-p', '--port PORT') { |v| options[:port] = v }
|
133
169
|
opt.on('-P', '--pid FILE') { |v| options[:pid] = v }
|
data/lib/garlando/version.rb
CHANGED
data/lib/guard/garlando.rb
CHANGED
data/spec/garlando_spec.rb
CHANGED
@@ -6,31 +6,31 @@ describe Garlando::CLI do
|
|
6
6
|
|
7
7
|
describe '#parse' do
|
8
8
|
it 'return command' do
|
9
|
-
commands, _ = cli.parse %w
|
9
|
+
commands, _ = cli.parse %w(start)
|
10
10
|
|
11
11
|
expect(commands).to eq ['start']
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'return options' do
|
15
|
-
_, options = cli.parse %w
|
15
|
+
_, options = cli.parse %w(-o 192.168.0.1)
|
16
16
|
|
17
|
-
expect(options[:
|
17
|
+
expect(options[:host]).to eq '192.168.0.1'
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe '#perform' do
|
22
|
-
before { Garlando::Server.
|
22
|
+
before { allow_any_instance_of(Garlando::Server).to receive(:call) }
|
23
23
|
|
24
24
|
it 'default command' do
|
25
|
-
|
25
|
+
expect_any_instance_of(Garlando::Server).to receive(:call).with(:restart)
|
26
26
|
|
27
|
-
|
27
|
+
cli.perform []
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'send command' do
|
31
|
-
|
31
|
+
expect_any_instance_of(Garlando::Server).to receive(:call).with(:foo)
|
32
32
|
|
33
|
-
|
33
|
+
cli.perform %w(foo)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -44,37 +44,44 @@ describe Garlando::Server do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'otherwise' do
|
47
|
-
server.stub start: nil
|
48
|
-
server.call :start
|
49
|
-
|
50
47
|
allow(server).to receive :start
|
48
|
+
expect(server).to receive :start
|
49
|
+
|
50
|
+
server.call :start
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
describe '#restart' do
|
55
|
-
before
|
55
|
+
before do
|
56
|
+
allow(server).to receive(:stop)
|
57
|
+
allow(server).to receive(:start)
|
58
|
+
allow(server).to receive(:running?) { true }
|
59
|
+
end
|
56
60
|
|
57
61
|
it 'call stop' do
|
58
|
-
server.
|
62
|
+
expect(server).to receive(:stop)
|
59
63
|
|
60
|
-
|
64
|
+
server.restart
|
61
65
|
end
|
62
66
|
|
63
67
|
it 'call start' do
|
64
|
-
server.
|
68
|
+
expect(server).to receive(:start)
|
65
69
|
|
66
|
-
|
70
|
+
server.restart
|
67
71
|
end
|
68
72
|
end
|
69
73
|
|
70
74
|
describe '#stop' do
|
71
75
|
context 'When server is not running' do
|
72
|
-
before
|
76
|
+
before do
|
77
|
+
allow(server).to receive(:running?) { false }
|
78
|
+
allow(server).to receive(:abort)
|
79
|
+
end
|
73
80
|
|
74
81
|
it 'return immediate' do
|
75
|
-
server.
|
82
|
+
expect(server).to receive(:abort).with('server is not running')
|
76
83
|
|
77
|
-
|
84
|
+
server.stop
|
78
85
|
end
|
79
86
|
end
|
80
87
|
|
@@ -86,17 +93,16 @@ describe Garlando::Server do
|
|
86
93
|
@temp.write pid
|
87
94
|
@temp.flush
|
88
95
|
|
89
|
-
server.
|
90
|
-
|
91
|
-
Process.stub(:kill) { raise Errno::ESRCH }
|
96
|
+
allow(server).to receive(:pid_path) { @temp.path }
|
97
|
+
allow(Process).to receive(:kill) { raise Errno::ESRCH }
|
92
98
|
end
|
93
99
|
|
94
100
|
after { @temp.close }
|
95
101
|
|
96
102
|
it 'send SIGINT to server' do
|
97
|
-
|
103
|
+
expect(Process).to receive(:kill).with(:INT, pid)
|
98
104
|
|
99
|
-
|
105
|
+
server.stop
|
100
106
|
end
|
101
107
|
end
|
102
108
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: garlando
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- miyucy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
66
|
rubyforge_project:
|
67
|
-
rubygems_version: 2.
|
67
|
+
rubygems_version: 2.4.4
|
68
68
|
signing_key:
|
69
69
|
specification_version: 4
|
70
70
|
summary: asset server
|