runcible 2.8.0 → 2.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 921c6c3a784e12f417dca5e350f9a14c33fcc395
4
- data.tar.gz: '08715f64e1fe52e30cd00e143c00e81cd3d9e017'
3
+ metadata.gz: 1752f5317fd0820a9fc61bb2979bc3530ef4c767
4
+ data.tar.gz: ff37b83265fa1a199b684d3115f212ab6823f2cb
5
5
  SHA512:
6
- metadata.gz: ad8a531d9c0aebfb534d6ca6240f45827861d124c809c6b68306f9e73f33385730a0fe74bfa5a1ebeb87782a59c40fcec5e83c5ace0b85c983029ba9445bf12b
7
- data.tar.gz: 1b180731fb71e91ebd5437bf12b24b6f4b2f1d42477d9ba05ccb85b15ec1eb1e0ebccbf43c4ce7438c2b4eed75b3aa27c5dc8a6c85591618143cd1bb0bef4a15
6
+ metadata.gz: 380df650cafb5fecb9b64696934c5cc83a1e092743857b917fd3dd1f17b102187ee42578c008522d473a2f0994ff91ea65991a29321688275333618ebb111bc9
7
+ data.tar.gz: acad017aa4ccff2a4c7744fcbc4f1b0d9c7eaaa4c5bd3333f62a51200bc02858a3b12072d34de379682f0ab72900d86a03a0535addb555acb2ae3b19f838b951
@@ -5,9 +5,12 @@ require 'thread'
5
5
 
6
6
  module Runcible
7
7
  class Base
8
+ attr_accessor :logs
9
+
8
10
  def initialize(config = {})
9
11
  @mutex = Mutex.new
10
12
  @config = config
13
+ @logs = []
11
14
  end
12
15
 
13
16
  def lazy_config=(a_block)
@@ -28,11 +31,11 @@ module Runcible
28
31
 
29
32
  # rubocop:disable Metrics/AbcSize:
30
33
  def call(method, path, options = {})
34
+ self.logs = []
31
35
  clone_config = self.config.clone
32
36
  #on occation path will already have prefix (sync cancel)
33
37
  path = clone_config[:api_path] + path unless path.start_with?(clone_config[:api_path])
34
38
 
35
- RestClient.log = []
36
39
  headers = clone_config[:headers].clone
37
40
 
38
41
  get_params = options[:params] if options[:params]
@@ -65,21 +68,29 @@ module Runcible
65
68
  args << generate_payload(options) if [:post, :put].include?(method)
66
69
  args << headers
67
70
 
71
+ self.logs << ([method.upcase, URI.join(client.url, path)] + args[1..-1]).join(': ')
68
72
  response = get_response(client, path, *args)
69
- process_response(response)
70
-
73
+ processed = process_response(response)
74
+ self.logs << "Response: #{response.code}: #{response.body}"
75
+ log_info
76
+ processed
71
77
  rescue RestClient::ResourceNotFound => e
78
+ self.logs << exception_to_log(e)
72
79
  log_info
73
80
  raise e
74
81
  rescue => e
82
+ self.logs << exception_to_log(e)
75
83
  log_exception
76
84
  raise e
77
85
  end
78
86
 
87
+ def exception_to_log(exception, body = exception.try(:response).try(:body))
88
+ "#{exception.message}: #{body}"
89
+ end
90
+
79
91
  def get_response(client, path, *args)
80
92
  client[path].send(*args) do |response, _request, _result, &_block|
81
93
  resp = response.return!
82
- log_debug
83
94
  return resp
84
95
  end
85
96
  end
@@ -135,8 +146,8 @@ module Runcible
135
146
  end
136
147
  end
137
148
  response = Runcible::Response.new(body, response)
138
- rescue JSON::ParserError
139
- log_exception
149
+ rescue JSON::ParserError => e
150
+ self.logs << "Unable to parse JSON: #{e.message}"
140
151
  end
141
152
 
142
153
  return response
@@ -188,28 +199,15 @@ module Runcible
188
199
  end
189
200
 
190
201
  def log_debug
191
- if self.config[:logging][:debug]
192
- log_message = generate_log_message
193
- self.config[:logging][:logger].debug(log_message)
194
- end
202
+ self.config[:logging][:logger].debug(self.logs.join("\n")) if self.config[:logging][:debug]
195
203
  end
196
204
 
197
205
  def log_exception
198
- if self.config[:logging][:exception]
199
- log_message = generate_log_message
200
- self.config[:logging][:logger].error(log_message)
201
- end
206
+ self.config[:logging][:logger].error(self.logs.join("\n")) if self.config[:logging][:exception]
202
207
  end
203
208
 
204
209
  def log_info
205
- if self.config[:logging][:info]
206
- log_message = generate_log_message
207
- self.config[:logging][:logger].info(log_message)
208
- end
209
- end
210
-
211
- def generate_log_message
212
- RestClient.log.join('\n')
210
+ self.config[:logging][:logger].info(self.logs.join("\n")) if self.config[:logging][:info]
213
211
  end
214
212
 
215
213
  def logger
@@ -1,3 +1,3 @@
1
1
  module Runcible
2
- VERSION = '2.8.0'.freeze
2
+ VERSION = '2.8.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runcible
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 2.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric D Helms, Justin Sherrill
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-03 00:00:00.000000000 Z
11
+ date: 2018-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  version: '0'
207
207
  requirements: []
208
208
  rubyforge_project:
209
- rubygems_version: 2.6.14.1
209
+ rubygems_version: 2.6.14
210
210
  signing_key:
211
211
  specification_version: 4
212
212
  summary: ''