cfoundry 0.3.34 → 0.3.35

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,9 @@ require "multi_json"
3
3
 
4
4
  module CFoundry
5
5
  class BaseClient # :nodoc:
6
+ LOG_FILE = File.expand_path("~/.cfoundry.log")
7
+ LOG_LENGTH = 10
8
+
6
9
  attr_accessor :trace, :no_backtrace
7
10
 
8
11
  def initialize(target, token = nil)
@@ -97,6 +100,7 @@ module CFoundry
97
100
 
98
101
  RestClient::Request.execute(req) do |response, request|
99
102
  print_trace(req, request, response, caller) if @trace
103
+ log_request(req, response)
100
104
  handle_response(response, accept)
101
105
  end
102
106
  rescue SocketError, Errno::ECONNREFUSED => e
@@ -164,6 +168,23 @@ module CFoundry
164
168
  }.join("/")
165
169
  end
166
170
 
171
+ def log_request(req, response)
172
+ file = File.expand_path(LOG_FILE)
173
+
174
+ if File.exists?(file)
175
+ log = File.readlines(file).last(LOG_LENGTH - 1)
176
+ end
177
+
178
+ File.open(file, "w") do |io|
179
+ log.each { |l| io.print l } if log
180
+ io.puts log_line(req, response.headers[:x_vcap_request_id])
181
+ end
182
+ end
183
+
184
+ def log_line(req, id)
185
+ "#{Time.now.strftime("%F %T")} #{id} #{req[:method].to_s.upcase.ljust(6)} #{req[:url]}"
186
+ end
187
+
167
188
  def print_trace(req, request, response, locs)
168
189
  $stderr.puts ">>>"
169
190
  $stderr.puts "PROXY: #{RestClient.proxy}" if RestClient.proxy
@@ -43,7 +43,13 @@ module CFoundry::V2
43
43
  end
44
44
 
45
45
  def stats
46
- @client.base.stats(@guid)
46
+ stats = {}
47
+
48
+ @client.base.stats(@guid).each do |idx, info|
49
+ stats[idx.to_s] = info
50
+ end
51
+
52
+ stats
47
53
  end
48
54
 
49
55
  def services
@@ -151,7 +151,7 @@ module CFoundry::V2
151
151
  }
152
152
 
153
153
  define_method(:"#{plural}=") { |xs|
154
- Model.validate_type(x, [CFoundry::V2.const_get(kls)])
154
+ Model.validate_type(xs, [CFoundry::V2.const_get(kls)])
155
155
 
156
156
  @manifest ||= {}
157
157
  @manifest[:entity] ||= {}
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.3.34"
3
+ VERSION = "0.3.35"
4
4
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfoundry
3
3
  version: !ruby/object:Gem::Version
4
- hash: 87
4
+ hash: 85
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 34
10
- version: 0.3.34
9
+ - 35
10
+ version: 0.3.35
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Suraci
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-09-18 00:00:00 Z
18
+ date: 2012-09-26 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rest-client