cuba-bin 0.2.2 → 0.3.0

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/cuba +23 -2
  3. data/lib/cuba/bin.rb +19 -3
  4. data/lib/cuba/bin/daemon.rb +80 -97
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4fe609d5f950f480489f5f6325f8b33a6b687db
4
- data.tar.gz: e686dba4ce27e60594116295868840966ffcd424
3
+ metadata.gz: 312a64509492c565429802098e203099dffb5e12
4
+ data.tar.gz: 109f742ac789908d251c9a6ff32bb110935d8b9a
5
5
  SHA512:
6
- metadata.gz: cf3608cd0c1c111364d164b26a7c85ce55342541189f5d9a06c7cf2b34925873a4a6f47c25580b6a0f2859aad0d0153974baf88b1729d82d5108809eda6f4cc0
7
- data.tar.gz: c4516fa6331ecada60431c06285aa391cc37f8ae043b401ed84ff3962200ecce9c51dbef7553cd2154d7a08c117d49cc01d9f5e15ace44d04000bc354e88a3ad
6
+ metadata.gz: dadeea0017b362c2b6733b59326f71a6dae7bd4b7c06f8a4b51b4a1166bc3b30b6b89d0ff8eff30e10e560903e98447610a554d01dde8fc6c4535738758e2cd1
7
+ data.tar.gz: d2734300ea9f69c7b427397581041633bd13ae08cd774191cb7ee8825265b6654385b0fa676faa97afc7d24e28c7185456d94f297a1d263981e0bc61006d32b0
data/bin/cuba CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  if ARGV.empty?
4
- puts "usage: cuba [s *args]"
4
+ puts "usage: cuba [server (s) *args] [deploy (d) *args]"
5
5
  exit
6
6
  end
7
7
 
@@ -11,6 +11,27 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
11
11
  require "cuba/bin"
12
12
  require "clap"
13
13
 
14
+ ENV['RACK_ENV'] ||= 'development'
15
+
16
+ env = '.env'
17
+ rack_env = "#{env}.#{ENV['RACK_ENV']}"
18
+
19
+ if File.file? rack_env
20
+ env = rack_env
21
+ elsif !File.file? env
22
+ env = false
23
+ end
24
+
25
+ if env
26
+ File.foreach env do |line|
27
+ key, value = line.split "="
28
+ ENV[key] = value.gsub('\n', '').strip
29
+ end
30
+ end
31
+
14
32
  Clap.run ARGV,
33
+ "server" => Cuba::Bin.method(:server),
15
34
  "s" => Cuba::Bin.method(:server),
16
- "-v" => -> { puts Cuba::Bin::VERSION }
35
+ "deploy" => Cuba::Bin.method(:deploy),
36
+ "d" => Cuba::Bin.method(:deploy),
37
+ "-v" => -> { puts Cuba::Bin::VERSION }
@@ -3,16 +3,32 @@ require "cuba/bin/daemon"
3
3
 
4
4
  module Cuba::Bin
5
5
  unless defined? VERSION
6
- VERSION = '0.2.2'
6
+ VERSION = '0.3.0'
7
7
  end
8
8
 
9
9
  extend self
10
10
 
11
11
  def server
12
- Daemon.new(argv).run
12
+ Daemon.new.run
13
13
  end
14
14
 
15
- private
15
+ def deploy
16
+ if ENV['CUBA_BIN_DEPLOY_PATH']
17
+ require ENV['CUBA_BIN_DEPLOY_PATH']
18
+ else
19
+ %w(config/deploy deploy).each do |file|
20
+ path = Dir.pwd + "/#{file}.rb"
21
+
22
+ if File.file? path
23
+ break require path
24
+ end
25
+ end
26
+ end
27
+
28
+ if defined? Deploy
29
+ Deploy.new.run
30
+ end
31
+ end
16
32
 
17
33
  def argv
18
34
  @args ||= begin
@@ -1,118 +1,101 @@
1
1
  require 'listen'
2
2
 
3
- module Cuba::Bin
4
- class Daemon
5
- extensions = %w(
6
- builder coffee creole css slim erb erubis jbuilder
7
- slim mote haml html js styl dom
8
- less liquid mab markdown md mdown mediawiki mkd mw
9
- nokogiri radius rb rdoc rhtml ru
10
- sass scss str textile txt wiki yajl yml
11
- env.*
12
- ).sort
13
-
14
- DEFAULT_RELOAD_PATTERN = %r(\.(?:builder #{extensions.join('|')})$)
15
-
16
- DEFAULT_FULL_RELOAD_PATTERN = /^Gemfile(?:\.lock)?$/
17
-
18
- # todo> make configurable
19
- IGNORE_PATTERNS = [/\.direnv/, /\.sass-cache/, /^tmp/]
20
-
21
- attr_accessor :options, :unicorn_args
22
- attr_accessor :unicorn_pid
23
-
24
- def initialize(unicorn_args)
25
- @unicorn_args = unicorn_args
26
- # @options, @unicorn_args = options, unicorn_args
27
- @options = {}
28
- options[:pattern] ||= DEFAULT_RELOAD_PATTERN
29
- options[:full] ||= DEFAULT_FULL_RELOAD_PATTERN
30
- options[:force_polling] ||= false
31
- self
32
- end
33
-
34
- def log(msg)
35
- $stderr.puts msg
36
- end
37
-
38
- def start_unicorn
39
- ENV['RACK_ENV'] ||= 'development'
40
-
41
- envs = {}
42
- env = '.env'
43
- rack_env = "#{env}.#{ENV['RACK_ENV']}"
44
-
45
- if File.file? rack_env
46
- env = rack_env
47
- elsif !File.file? env
48
- env = false
3
+ class Cuba
4
+ module Bin
5
+ class Daemon
6
+ extensions = %w(
7
+ builder coffee creole css slim erb erubis jbuilder
8
+ slim mote haml html js styl dom
9
+ less liquid mab markdown md mdown mediawiki mkd mw
10
+ nokogiri radius rb rdoc rhtml ru
11
+ sass scss str textile txt wiki yajl yml
12
+ env.*
13
+ ).sort
14
+
15
+ DEFAULT_RELOAD_PATTERN = %r(\.(?:builder #{extensions.join('|')})$)
16
+
17
+ DEFAULT_FULL_RELOAD_PATTERN = /^Gemfile(?:\.lock)?$/
18
+
19
+ # todo> make configurable
20
+ IGNORE_PATTERNS = [/\.direnv/, /\.sass-cache/, /^tmp/]
21
+
22
+ attr_accessor :options, :unicorn_args
23
+ attr_accessor :unicorn_pid
24
+
25
+ def initialize
26
+ @unicorn_args = Bin.argv
27
+ # @options, @unicorn_args = options, unicorn_args
28
+ @options = {}
29
+ options[:pattern] ||= DEFAULT_RELOAD_PATTERN
30
+ options[:full] ||= DEFAULT_FULL_RELOAD_PATTERN
31
+ options[:force_polling] ||= false
32
+ self
49
33
  end
50
34
 
51
- if env
52
- File.foreach env do |line|
53
- key, value = line.split "="
54
- envs[key] = value.gsub('\n', '').strip
55
- end
35
+ def log(msg)
36
+ $stderr.puts msg
56
37
  end
57
38
 
58
- @unicorn_pid = Kernel.spawn(envs, 'unicorn', '-c', unicorn_config, *unicorn_args)
59
- end
39
+ def start_unicorn
40
+ @unicorn_pid = Kernel.spawn('unicorn', '-c', unicorn_config, *unicorn_args)
41
+ end
60
42
 
61
- def unicorn_config
62
- File.expand_path 'unicorn.conf.rb', File.dirname(__FILE__)
63
- end
43
+ def unicorn_config
44
+ File.expand_path 'unicorn.conf.rb', File.dirname(__FILE__)
45
+ end
64
46
 
65
- # TODO maybe consider doing like: http://unicorn.bogomips.org/SIGNALS.html
66
- def reload_everything
67
- Process.kill(:QUIT, unicorn_pid)
68
- Process.wait(unicorn_pid)
69
- start_unicorn
70
- end
47
+ # TODO maybe consider doing like: http://unicorn.bogomips.org/SIGNALS.html
48
+ def reload_everything
49
+ Process.kill(:QUIT, unicorn_pid)
50
+ Process.wait(unicorn_pid)
51
+ start_unicorn
52
+ end
71
53
 
72
- def shutdown
73
- listener.stop
74
- Process.kill(:TERM, unicorn_pid)
75
- Process.wait(unicorn_pid)
76
- exit
77
- end
54
+ def shutdown
55
+ listener.stop
56
+ Process.kill(:TERM, unicorn_pid)
57
+ Process.wait(unicorn_pid)
58
+ exit
59
+ end
78
60
 
79
- # tell unicorn to gracefully shut down workers
80
- def hup_unicorn
81
- log "hupping #{unicorn_pid}"
82
- Process.kill(:HUP, unicorn_pid)
83
- end
61
+ # tell unicorn to gracefully shut down workers
62
+ def hup_unicorn
63
+ log "hupping #{unicorn_pid}"
64
+ Process.kill(:HUP, unicorn_pid)
65
+ end
84
66
 
85
- def handle_change(modified, added, removed)
86
- log "File change event detected: #{{modified: modified, added: added, removed: removed}.inspect}"
67
+ def handle_change(modified, added, removed)
68
+ log "File change event detected: #{{modified: modified, added: added, removed: removed}.inspect}"
87
69
 
88
- if (modified + added + removed).index {|f| f =~ options[:full]}
89
- reload_everything
90
- else
91
- hup_unicorn
70
+ if (modified + added + removed).index {|f| f =~ options[:full]}
71
+ reload_everything
72
+ else
73
+ hup_unicorn
74
+ end
92
75
  end
93
- end
94
76
 
95
- def listener
96
- @listener ||= begin
97
- x = Listen.to(Dir.pwd, :relative_paths=>true, :force_polling=> options[:force_polling]) do |modified, added, removed|
98
- handle_change(modified, added, removed)
99
- end
77
+ def listener
78
+ @listener ||= begin
79
+ x = Listen.to(Dir.pwd, :relative_paths=>true, :force_polling=> options[:force_polling]) do |modified, added, removed|
80
+ handle_change(modified, added, removed)
81
+ end
100
82
 
101
- x.only([ options[:pattern], options[:full] ])
102
- IGNORE_PATTERNS.map{|ptrn| x.ignore(ptrn) }
103
- x
83
+ x.only([ options[:pattern], options[:full] ])
84
+ IGNORE_PATTERNS.map{|ptrn| x.ignore(ptrn) }
85
+ x
86
+ end
104
87
  end
105
- end
106
88
 
107
- def run
108
- that = self
109
- Signal.trap("INT") { |signo| that.shutdown }
110
- Signal.trap("EXIT") { |signo| that.shutdown }
111
- listener.start
112
- start_unicorn
89
+ def run
90
+ that = self
91
+ Signal.trap("INT") { |signo| that.shutdown }
92
+ Signal.trap("EXIT") { |signo| that.shutdown }
93
+ listener.start
94
+ start_unicorn
113
95
 
114
- # And now we just want to keep the thread alive--we're just waiting around to get interrupted at this point.
115
- sleep(99999) while true
96
+ # And now we just want to keep the thread alive--we're just waiting around to get interrupted at this point.
97
+ sleep(99999) while true
98
+ end
116
99
  end
117
100
  end
118
101
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuba-bin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - cj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-11 00:00:00.000000000 Z
11
+ date: 2014-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cuba