workon 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/workon.rb +1 -1
- data/lib/workon/actor.rb +14 -6
- data/lib/workon/actor/base.rb +6 -4
- data/lib/workon/actor/middleman.rb +3 -2
- data/lib/workon/actor/passenger.rb +6 -1
- data/lib/workon/actor/web_browser.rb +17 -2
- data/lib/workon/configuration.rb +33 -0
- data/lib/workon/version.rb +1 -1
- metadata +1 -1
data/lib/workon.rb
CHANGED
data/lib/workon/actor.rb
CHANGED
@@ -7,22 +7,30 @@ module Workon
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.before(actor = nil, other = nil)
|
10
|
-
@before ||= {}
|
10
|
+
@before ||= Hash.new { [] }
|
11
11
|
|
12
12
|
return @before if actor.nil?
|
13
13
|
raise ArgumentError if other.nil?
|
14
14
|
|
15
|
-
@before[other]
|
15
|
+
@before[other] += [actor]
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.ordered
|
19
19
|
order ||= Workon::Actor::Base.subclasses.inject([]) do |memo, klass|
|
20
|
-
|
21
|
-
|
22
|
-
should_add = !Workon.config[:without].include?(finder) && !memo.include?(klass)
|
20
|
+
other = encompass klass
|
21
|
+
should_add = !Workon.config[:without].include?(klass.actor_name) && !memo.include?(klass)
|
23
22
|
|
24
|
-
should_add ? memo +
|
23
|
+
should_add ? memo + other : memo
|
25
24
|
end
|
25
|
+
|
26
|
+
order
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.encompass(klass)
|
30
|
+
finder = klass.actor_name.to_sym
|
31
|
+
_before = before[finder].map {|k| encompass k }
|
32
|
+
|
33
|
+
(_before + [klass]).flatten
|
26
34
|
end
|
27
35
|
end
|
28
36
|
end
|
data/lib/workon/actor/base.rb
CHANGED
@@ -27,6 +27,10 @@ module Workon
|
|
27
27
|
Workon::Actor.before self, other
|
28
28
|
end
|
29
29
|
|
30
|
+
def self.actor_name
|
31
|
+
name.split('::').last
|
32
|
+
end
|
33
|
+
|
30
34
|
def initialize(path)
|
31
35
|
@path = path
|
32
36
|
end
|
@@ -36,13 +40,11 @@ module Workon
|
|
36
40
|
end
|
37
41
|
|
38
42
|
def has_option?(key)
|
39
|
-
|
40
|
-
|
41
|
-
!options[key].nil? && (options[key] || !options[key].empty?)
|
43
|
+
options.exists? key
|
42
44
|
end
|
43
45
|
|
44
46
|
def fetch_option(key, default = nil)
|
45
|
-
|
47
|
+
options.fetch key, default
|
46
48
|
end
|
47
49
|
|
48
50
|
def project
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module Workon
|
2
2
|
module Actor
|
3
3
|
class Middleman < Base
|
4
|
+
before :WebBrowser
|
4
5
|
option('--middleman', 'Start mm-server') { |v| options[:middleman] = true }
|
5
6
|
|
6
7
|
def commit
|
7
8
|
if fetch_option :middleman, false
|
8
|
-
|
9
|
-
|
9
|
+
port = fetch_option :port, 4567
|
10
|
+
screen "mm-server --port #{port}"
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Workon
|
2
2
|
module Actor
|
3
3
|
class Passenger < Base
|
4
|
+
before :WebBrowser
|
5
|
+
|
4
6
|
def is_rack_app?
|
5
7
|
!Dir['config.ru'].empty?
|
6
8
|
end
|
@@ -10,7 +12,10 @@ module Workon
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def commit
|
13
|
-
|
15
|
+
if is_rack_app? && passenger_standalone_available?
|
16
|
+
port = fetch_option :port, 3000
|
17
|
+
screen "passenger start --port #{port}"
|
18
|
+
end
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
@@ -2,10 +2,25 @@ module Workon
|
|
2
2
|
module Actor
|
3
3
|
class WebBrowser < Base
|
4
4
|
option('--host HOST', 'Ping this host') { |v| options[:host] = v}
|
5
|
+
option('--port PORT', Integer, 'Use this port for Middleman/Passenger') { |v| options[:port] = v}
|
5
6
|
|
6
7
|
def command
|
7
|
-
host_name
|
8
|
-
|
8
|
+
host_name = fetch_option :host, %{#{project}.local}
|
9
|
+
port_number = fetch_option :port, nil
|
10
|
+
|
11
|
+
command, qualified = port_number.nil? ? ping_test(host_name) : netstat_test(port_number)
|
12
|
+
%{#{command} && open http://#{qualified}}
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def ping_test(host_name)
|
17
|
+
command = %{ping -q -c 1 -t 1 #{host_name}}
|
18
|
+
[ command, host_name ]
|
19
|
+
end
|
20
|
+
|
21
|
+
def netstat_test(port)
|
22
|
+
command = %{sleep 3 && netstat -na | egrep 'tcp4*6* +([0-9]+ +){2}(\\*|([0-9]+\\.)+[0-9]+)(:|\\.)#{port}'}
|
23
|
+
[ command, "localhost:#{port}" ]
|
9
24
|
end
|
10
25
|
end
|
11
26
|
end
|
data/lib/workon/configuration.rb
CHANGED
@@ -20,6 +20,34 @@ module Workon
|
|
20
20
|
options[:project] = args.first unless args.empty?
|
21
21
|
end
|
22
22
|
|
23
|
+
def exists?(key)
|
24
|
+
key = key.to_sym
|
25
|
+
!blank? options[key]
|
26
|
+
end
|
27
|
+
|
28
|
+
def set(key, value)
|
29
|
+
key = key.to_sym
|
30
|
+
options[key] = value
|
31
|
+
end
|
32
|
+
|
33
|
+
def fetch(key, default = nil)
|
34
|
+
key = key.to_sym
|
35
|
+
|
36
|
+
if !exists?(key) && !blank?(default)
|
37
|
+
set key, default
|
38
|
+
end
|
39
|
+
|
40
|
+
options[key]
|
41
|
+
end
|
42
|
+
|
43
|
+
def [](key)
|
44
|
+
fetch key
|
45
|
+
end
|
46
|
+
|
47
|
+
def []=(key, value)
|
48
|
+
set key, value
|
49
|
+
end
|
50
|
+
|
23
51
|
def parser
|
24
52
|
@parser ||= OptionParser.new do |o|
|
25
53
|
o.banner = "Usage: #{File.basename($0)} [options] project"
|
@@ -84,5 +112,10 @@ module Workon
|
|
84
112
|
STDERR.puts %(Could not save workon configuration to #{project_rc_path})
|
85
113
|
end
|
86
114
|
end
|
115
|
+
|
116
|
+
private
|
117
|
+
def blank?(object)
|
118
|
+
object.respond_to?(:empty?) ? object.empty? : !object
|
119
|
+
end
|
87
120
|
end
|
88
121
|
end
|
data/lib/workon/version.rb
CHANGED