garlando 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6cfa5cad9a4e1f969113e9075792514547862b16
4
- data.tar.gz: 32a0b2154abaab7a0bf8bf00003a47a60d9e6832
3
+ metadata.gz: 7caf226a549137d06499593a0fc968acca5aaa68
4
+ data.tar.gz: 3be821e59ccd449cd81c43aed644bd920522ce28
5
5
  SHA512:
6
- metadata.gz: a2b9f94307c4d637bc185c2fca8d8862793871735cfefda4401904e8dd8f94bdbebb4d788b7085f2b1e3553e478961b99683b4c3f750124a884382655e3c413f
7
- data.tar.gz: 4f5a43b9b150036dfeadfca2453936cd404907f1b74a0a5dfeeaf3823c236d08b6d09cff699c5f055fde5c4bc755a7eaad638c3400300058705f8ea6e9a92b09
6
+ metadata.gz: 49a6825840e4cfd913829325a518f6451c64c91de9d09fb58fc23fed89755dbdfcfa353e6f7223b29f6c944df8e6ad08312f36107eeafda03fbd2d77b82c37ea
7
+ data.tar.gz: 1c07f8f67e3f5503719a87b4fa5a662f1bb142bc3cf4adba047c43e05d62ed42fff98cd48134f2b687ef612ee42316fdac1a56c17952599c1ef091502fa76529
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Yuki MIYAUCHI
1
+ Copyright (c) 2014 miyucy
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -22,7 +22,7 @@ TODO: Write usage instructions here
22
22
 
23
23
  ## Contributing
24
24
 
25
- 1. Fork it ( http://github.com/<my-github-username>/garlando/fork )
25
+ 1. Fork it ( http://github.com/miyucy/garlando/fork )
26
26
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
27
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
28
  4. Push to the branch (`git push origin my-new-feature`)
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["fistfvck@gmail.com"]
11
11
  spec.summary = %q{asset server}
12
12
  spec.description = %q{asset server}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/miyucy/garlando"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -6,12 +6,13 @@ module Garlando
6
6
  class Server
7
7
  COMMANDS = %i[start restart stop status]
8
8
  OPTIONS = {
9
- server: 'thin',
9
+ env: 'development',
10
10
  host: '0.0.0.0',
11
+ log: 'log/garlando.log',
12
+ pid: 'tmp/pids/garlando.pid',
11
13
  port: 65501,
12
- pid: 'tmp/pids/asset_server.pid',
13
- env: 'development',
14
14
  pwd: Dir.pwd,
15
+ server: 'thin',
15
16
  }
16
17
 
17
18
  def initialize(options={})
@@ -24,7 +25,7 @@ module Garlando
24
25
  end
25
26
 
26
27
  def start
27
- abort 'server is already running?' if File.exists? pid_path
28
+ abort 'server is already running?' if running?
28
29
  abort "File could not found (#{env_path})" unless File.exists?(env_path)
29
30
 
30
31
  Process.daemon nochdir = true
@@ -32,37 +33,36 @@ module Garlando
32
33
  File.write pid_path, Process.pid.to_s
33
34
  at_exit { File.unlink pid_path }
34
35
 
36
+ reopen
37
+
35
38
  ENV['RACK_ENV'] = @options[:env]
36
39
  require env_path
37
40
 
38
- app = Rack::URLMap.new Rails.application.config.assets[:prefix] => Rails.application.assets
39
- srv = Rack::Handler.pick @options[:server]
40
- srv.run app, Host: @options[:host], Port: @options[:port]
41
+ server.run application, Host: @options[:host], Port: @options[:port]
41
42
  end
42
43
 
43
- def stop(aborting = true)
44
- unless File.exists?(pid_path)
45
- return unless aborting
46
- abort 'server is not running'
47
- end
44
+ def stop
45
+ return abort 'server is not running' unless running?
48
46
 
49
47
  pid = File.read(pid_path).to_i
50
48
  Timeout.timeout(10) do
51
- loop do
52
- break unless system "ps -p #{pid} > /dev/null"
53
- Process.kill :INT, pid
54
- sleep 0.5
49
+ begin
50
+ while running?
51
+ Process.kill :INT, pid
52
+ sleep 0.5
53
+ end
54
+ rescue Errno::ESRCH
55
55
  end
56
56
  end
57
57
  end
58
58
 
59
59
  def restart
60
- stop aborting = false
60
+ stop if running?
61
61
  start
62
62
  end
63
63
 
64
64
  def status
65
- if File.exists? pid_path
65
+ if running?
66
66
  puts "server is running (#{File.read pid_path})"
67
67
  else
68
68
  puts 'server is not running'
@@ -71,6 +71,10 @@ module Garlando
71
71
 
72
72
  private
73
73
 
74
+ def running?
75
+ File.exists? pid_path
76
+ end
77
+
74
78
  def pid_path
75
79
  File.join @options[:pwd], @options[:pid]
76
80
  end
@@ -78,6 +82,23 @@ module Garlando
78
82
  def env_path
79
83
  File.join @options[:pwd], 'config/environment.rb'
80
84
  end
85
+
86
+ def reopen
87
+ file = File.open File.join(@options[:pwd], @options[:log]), 'w+'
88
+ [STDOUT, STDERR].each { |e| e.reopen file }
89
+ end
90
+
91
+ def server
92
+ Rack::Handler.get @options[:server]
93
+ end
94
+
95
+ def application
96
+ Rack::URLMap.new rails.config.assets[:prefix] => rails.assets
97
+ end
98
+
99
+ def rails
100
+ Rails.application
101
+ end
81
102
  end
82
103
 
83
104
  class CLI
@@ -1,3 +1,3 @@
1
1
  module Garlando
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'tempfile'
2
3
 
3
4
  describe Garlando::CLI do
4
5
  let(:cli) { Garlando::CLI.new }
@@ -18,16 +19,15 @@ describe Garlando::CLI do
18
19
  end
19
20
 
20
21
  describe '#perform' do
22
+ before { Garlando::Server.any_instance.stub(:call) }
23
+
21
24
  it 'default command' do
22
- Garlando::Server.any_instance.stub(:call)
23
- # Garlando::Server.stub(new: true)
24
25
  cli.perform %w[]
25
26
 
26
27
  allow_any_instance_of(Garlando::Server).to receive(:call).with(:restart)
27
28
  end
28
29
 
29
30
  it 'send command' do
30
- Garlando::Server.any_instance.stub(:call)
31
31
  cli.perform %w[foo]
32
32
 
33
33
  allow_any_instance_of(Garlando::Server).to receive(:call).with(:foo)
@@ -66,4 +66,38 @@ describe Garlando::Server do
66
66
  allow(server).to receive(:start)
67
67
  end
68
68
  end
69
+
70
+ describe '#stop' do
71
+ context 'When server is not running' do
72
+ before { server.stub running?: false, abort: nil }
73
+
74
+ it 'return immediate' do
75
+ server.stop
76
+
77
+ allow(server).to receive(:abort).with('server is not running')
78
+ end
79
+ end
80
+
81
+ context 'When server is running' do
82
+ let(:pid) { 1234567890 }
83
+
84
+ before do
85
+ @temp = Tempfile.new 'garlando'
86
+ @temp.write pid
87
+ @temp.flush
88
+
89
+ server.stub pid_path: @temp.path
90
+
91
+ Process.stub(:kill) { raise Errno::ESRCH }
92
+ end
93
+
94
+ after { @temp.close }
95
+
96
+ it 'send SIGINT to server' do
97
+ server.stop
98
+
99
+ allow(Process).to receive(:kill).with(:INT, pid)
100
+ end
101
+ end
102
+ end
69
103
  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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - miyucy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-29 00:00:00.000000000 Z
11
+ date: 2014-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -43,7 +43,7 @@ files:
43
43
  - lib/garlando/version.rb
44
44
  - spec/garlando_spec.rb
45
45
  - spec/spec_helper.rb
46
- homepage: ''
46
+ homepage: https://github.com/miyucy/garlando
47
47
  licenses:
48
48
  - MIT
49
49
  metadata: {}