goat 0.3.6 → 0.3.7

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.
data/bin/channel-srv CHANGED
@@ -27,7 +27,7 @@ module Goat
27
27
  if pusher
28
28
  pusher.statesrv_message_received(msg)
29
29
  else
30
- logw "Page #{msg['pgid'].inspect} doesn't appear to be connected to this chsrv"
30
+ Goat.logw "Page #{msg['pgid'].inspect} doesn't appear to be connected to this chsrv"
31
31
  end
32
32
  end
33
33
  end
@@ -80,7 +80,7 @@ module Goat
80
80
  end
81
81
 
82
82
  def cleanup
83
- logw "connection for #{@pgid}/#{@jsonp} closed"
83
+ Goat.logw "connection for #{@pgid}/#{@jsonp} closed"
84
84
  @finished = true
85
85
  self.class.pushers.delete(pgid)
86
86
  @channel.unsubscribe(@sub) if @sub
data/bin/state-srv CHANGED
@@ -73,7 +73,7 @@ module Goat
73
73
  @last_connected[pgid] = Time.now
74
74
  @page_connections[pgid] = {:chsrv => chsrv, :version => ver}
75
75
  else
76
- logw "Page #{pgid} has been deleted"
76
+ Goat.logw "Page #{pgid} has been deleted"
77
77
  raise PageDeleted
78
78
  end
79
79
  end
@@ -122,7 +122,7 @@ module Goat
122
122
  if cs
123
123
  cs.each {|c| delete_component(c)}
124
124
  else
125
- logw "(No components for #{pgid})"
125
+ Goat.logw "(No components for #{pgid})"
126
126
  end
127
127
 
128
128
  @page_updates.delete(pgid)
@@ -200,7 +200,7 @@ module Goat
200
200
  @registry.add_component(pgid, ComponentSkeleton.from_hash(c))
201
201
  end
202
202
 
203
- logd("registered #{msg['components'].count} components")
203
+ Goat.logd("registered #{msg['components'].count} components")
204
204
 
205
205
  @registry.initialize_page(pgid)
206
206
 
@@ -230,7 +230,7 @@ module Goat
230
230
  if chsrv
231
231
  chsrv.send_message(type, msg)
232
232
  else
233
- logw "send_message fail: #{chsrv_id} no longer connected"
233
+ Goat.logw "send_message fail: #{chsrv_id} no longer connected"
234
234
  end
235
235
  end
236
236
 
@@ -264,7 +264,7 @@ module Goat
264
264
 
265
265
  send_message(chsrv_id, 'page_updated', {'pgid' => pgid, 'messages' => msgs}) unless msgs.empty?
266
266
  else
267
- logw "No chsrv connection for page #{pgid}"
267
+ Goat.logw "No chsrv connection for page #{pgid}"
268
268
  end
269
269
  end
270
270
 
@@ -342,7 +342,7 @@ module Goat
342
342
  def run
343
343
  @registry.connected_pages.each do |pgid|
344
344
  if @registry.last_connected_delta(pgid) > 300
345
- logd "Deleting page #{pgid}"
345
+ Goat.logd "Deleting page #{pgid}"
346
346
  @registry.delete_page(pgid)
347
347
  end
348
348
  end
@@ -365,7 +365,7 @@ module Goat
365
365
  if type == 'register_chsrv'
366
366
  Delegate.register_chsrv(self, msg)
367
367
  @chsrv = msg
368
- logw "#{@chsrv['chsrv']} connected"
368
+ Goat.logw "#{@chsrv['chsrv']} connected"
369
369
  elsif Delegate.respond_to?(type)
370
370
  if resp = Delegate.send(type, msg)
371
371
  send_message('response', 'response' => resp)
@@ -387,7 +387,7 @@ module Goat
387
387
 
388
388
  def unbind
389
389
  if @chsrv
390
- logw "#{@chsrv['chsrv']} disconnected"
390
+ Goat.logw "#{@chsrv['chsrv']} disconnected"
391
391
  Delegate.unregister_chsrv(self, @chsrv)
392
392
  end
393
393
  end
data/goat.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'goat'
3
- s.version = '0.3.6'
3
+ s.version = '0.3.7'
4
4
  s.summary = 'Pre-release beta version of Goat'
5
5
  s.author = 'Patrick Collison'
6
6
  s.email = 'patrick@collison.ie'
data/lib/goat.rb CHANGED
@@ -62,6 +62,8 @@ end
62
62
  module Goat
63
63
  class HTMLString < String; end
64
64
 
65
+ include Goat::Log
66
+
65
67
  class << self
66
68
  inline do |builder|
67
69
  builder.c 'VALUE new_without_initialize(VALUE klass) {
@@ -176,7 +178,7 @@ module Goat
176
178
  @messages = []
177
179
 
178
180
  self.errback do
179
- logd "Channel closed"
181
+ Goat.logd "Channel closed"
180
182
  @finished = true
181
183
  end
182
184
 
@@ -306,8 +308,8 @@ module Goat
306
308
  @error_handler_binding ||= App.bind(app.class.error_handler)
307
309
  resp = @error_handler_binding.call(app, e)
308
310
  else
309
- loge e.inspect
310
- loge e.backtrace.join("\n")
311
+ Goat.loge e.inspect
312
+ Goat.loge e.backtrace.join("\n")
311
313
 
312
314
  resp = Rack::Response.new
313
315
  resp.status = 500
@@ -630,7 +632,7 @@ module Goat
630
632
  kls = app.class
631
633
 
632
634
  unless kls.instance_methods.include?(mname)
633
- logd "defining #{mname} on #{kls}"
635
+ Goat.logd "defining #{mname} on #{kls}"
634
636
  kls.send(:define_method, mname, hook)
635
637
  hook = kls.instance_method(mname)
636
638
  end
@@ -1,29 +1,29 @@
1
1
  require 'term/ansicolor'
2
2
 
3
- module Log
4
- def self.logname; File.basename($0); end
5
- def self.logpath; "/tmp/#{logname}.log"; end
6
- def self.lockpath; "/tmp/#{logname}.lock"; end
7
- def self.logf; @log ||= File.open(logpath, 'a'); end
3
+ module Goat
4
+ def self.logd(msg); Log.log(:debug, msg); end
5
+ def self.logw(msg); Log.log(:warn, msg); end
6
+ def self.loge(msg); Log.log(:error, msg); end
8
7
 
9
- def self.log(lvl, msg, termmsg=nil)
10
- logf.puts("#{Time.now.asctime} #{msg}")
11
- logf.flush
8
+ module Log
9
+ def self.logname; File.basename($0); end
10
+ def self.logpath; "/tmp/#{logname}.log"; end
11
+ def self.lockpath; "/tmp/#{logname}.lock"; end
12
+ def self.logf; @log ||= File.open(logpath, 'a'); end
12
13
 
13
- termmsg ||= msg
14
- $stderr.puts(termmsg[0..90])
15
- end
14
+ def self.log(lvl, msg, termmsg=nil)
15
+ logf.puts("#{Time.now.asctime} #{msg}")
16
+ logf.flush
16
17
 
17
- def self.log_message(msg)
18
- log("#{msg['type']} #{msg.inspect}", "#{Term::ANSIColor.green(msg['type'])}: #{msg.inspect}")
19
- end
20
- end
18
+ termmsg ||= msg
19
+ $stderr.puts(termmsg[0..90])
20
+ end
21
21
 
22
- def logd(msg); Log.log(:debug, msg); end
23
- def logw(msg); Log.log(:warn, msg); end
24
- def loge(msg); Log.log(:error, msg); end
22
+ def self.log_message(msg)
23
+ log("#{msg['type']} #{msg.inspect}", "#{Term::ANSIColor.green(msg['type'])}: #{msg.inspect}")
24
+ end
25
+ end
25
26
 
26
- module Goat
27
27
  # for use with EM::Connection
28
28
  module JSONMessages
29
29
  def send_message(type, msg)
@@ -8,7 +8,7 @@ module Goat
8
8
  def self.start(host, port)
9
9
  EM.connect(host, port, self)
10
10
  rescue RuntimeError => e
11
- log :live, "Couldn't connect to notification server at #{host}:#{port}"
11
+ Goat.log :live, "Couldn't connect to notification server at #{host}:#{port}"
12
12
  raise e
13
13
  end
14
14
 
@@ -17,7 +17,7 @@ module Goat
17
17
  end
18
18
 
19
19
  def unbind
20
- logw "Lost notification server connection"
20
+ Goat.logw "Lost notification server connection"
21
21
  EM.add_timer(1) do
22
22
  NotificationCenter.start_receiver
23
23
  end
@@ -63,7 +63,7 @@ module Goat
63
63
  def self.receive(line)
64
64
  notif = load_notif(line)
65
65
  nid = notif['_nid']
66
- logd "received notif #{notif.inspect}" if $verbose
66
+ Goat.logd "received notif #{notif.inspect}" if $verbose
67
67
 
68
68
  raise "No _nid" unless nid
69
69
 
@@ -56,7 +56,7 @@ module Goat
56
56
  s = TCPSocket.open(@host, @port)
57
57
  s.write(msg.to_json + "\n")
58
58
  resp = s.readline
59
- logd("=> #{resp.inspect}") if $verbose
59
+ Goat.logd("=> #{resp.inspect}") if $verbose
60
60
  s.close
61
61
  resp
62
62
  end
@@ -73,14 +73,14 @@ module Goat
73
73
 
74
74
  def connection_completed
75
75
  @was_connected = true
76
- logw "Connected to StateSrv"
76
+ Goat.logw "Connected to StateSrv"
77
77
  StateSrvConnection.connection = self
78
78
  end
79
79
 
80
80
  def receive_line(line)
81
81
  msg = JSON.load(line)
82
82
 
83
- logd("=> #{msg.inspect}") if $verbose
83
+ Goat.logd("=> #{msg.inspect}") if $verbose
84
84
 
85
85
  if msg.is_a?(Array)
86
86
  msg.each{|m| message_received(m)}
@@ -92,7 +92,7 @@ module Goat
92
92
  def send_message(t, msg, sync=false)
93
93
  msg = msg.merge('type' => t)
94
94
 
95
- logd(">> #{msg.inspect}") if $verbose
95
+ Goat.logd(">> #{msg.inspect}") if $verbose
96
96
 
97
97
  if sync
98
98
  self.class.send_message_sync(msg) # TODO better way to do this?
@@ -107,9 +107,9 @@ module Goat
107
107
 
108
108
  def unbind
109
109
  if @was_connected
110
- logw "Lost StateSrv connection"
110
+ Goat.logw "Lost StateSrv connection"
111
111
  else
112
- logw "Couldn't open StateSrv connection"
112
+ Goat.logw "Couldn't open StateSrv connection"
113
113
  end
114
114
 
115
115
  StateSrvConnection.connection = nil
data/lib/goat/yodel.rb CHANGED
@@ -13,7 +13,7 @@ module Yodel
13
13
  end
14
14
 
15
15
  def post_init
16
- logw "listener connected"
16
+ Goat.logw "listener connected"
17
17
  @sub = NotifChannel.subscribe do |msg|
18
18
  send_data(msg + "\n")
19
19
  end
@@ -32,7 +32,7 @@ module Yodel
32
32
  end
33
33
 
34
34
  def receive_line(line)
35
- logd "got #{line}"
35
+ Goat.logd "got #{line}"
36
36
  NotifChannel << line
37
37
  end
38
38
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goat
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 6
10
- version: 0.3.6
9
+ - 7
10
+ version: 0.3.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Patrick Collison