duoconsole 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/duoconsole.rb +29 -15
  2. metadata +2 -2
data/lib/duoconsole.rb CHANGED
@@ -119,7 +119,14 @@ class Duoconsole
119
119
  @socket = socket
120
120
  end
121
121
 
122
- def send msg
122
+ def method_missing(m, *args, &block)
123
+ send m, args
124
+ end
125
+
126
+ private
127
+
128
+ def send command, args
129
+ msg = Marshal.dump([command, args])
123
130
  socket.write(msg)
124
131
  recv
125
132
  end
@@ -133,14 +140,11 @@ class Duoconsole
133
140
  socket.recv(1000)
134
141
  raise e
135
142
  end
136
-
137
- def method_missing(m, *args, &block)
138
- send "#{m} #{args.join(' ')}"
139
- end
140
143
  end
141
144
 
142
145
 
143
146
  class CommandServer
147
+ RECOGNIZED_COMMANDS = [:test, :rake]
144
148
  attr_reader :socket
145
149
 
146
150
  def initialize socket
@@ -150,29 +154,39 @@ class Duoconsole
150
154
  def start
151
155
  loop do
152
156
  msg = socket.recv(1000)
153
- command, args = get_command_and_args msg
157
+ command, args = Marshal.load(msg)
154
158
 
155
- retval = if commander.respond_to?(command)
156
- commander.send(command, args)
159
+ retval = if valid_command?(command)
160
+ run_command(command, args)
157
161
  else
158
- 'Unrecognized command'
162
+ "Unrecognized command. Valid commands are #{RECOGNIZED_COMMANDS.join(', ')}"
159
163
  end
160
164
 
161
165
  socket.write(retval)
162
166
  end
163
167
  end
164
168
 
165
- def get_command_and_args msg
166
- parts = msg.split(' ')
167
- command = parts.shift
168
- args = parts.join(' ')
169
- args = nil unless args.match(/\S/)
170
- [command, args]
169
+ private
170
+
171
+ def valid_command? command
172
+ RECOGNIZED_COMMANDS.include?(command.to_sym)
173
+ end
174
+
175
+ def run_command command, args
176
+ commander.send(command, *args)
177
+ rescue => e
178
+ dump_exception e
179
+ e.class.name
171
180
  end
172
181
 
173
182
  def commander
174
183
  @commander ||= Rails::Commands::Commander.new
175
184
  end
185
+
186
+ def dump_exception e
187
+ puts "#{e.class}: #{e.message}"
188
+ puts e.backtrace.map {|line| "\t#{line}"}
189
+ end
176
190
  end
177
191
 
178
192
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duoconsole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-01 00:00:00.000000000 Z
12
+ date: 2013-01-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails