rack-webprofiler 0.1.1 → 0.1.2

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: 96dfb4d501418608de8496058d100f1006e7f616
4
- data.tar.gz: 4f0b768c2127d7106d9b22c23605f33e59e0915a
3
+ metadata.gz: fd396a0c74f2907da4a53e8ecd201d49b90cca65
4
+ data.tar.gz: f5f48a8a2545e4721ebed61e239dc645632525fc
5
5
  SHA512:
6
- metadata.gz: 0f295760200944bd1e04c5de3aae9278f7ba853928125b9b3f3093df1d813252d3090fdd0e061c876deeaaf577e8604d56cfb41b3800065b117dd64c2cf7c0c3
7
- data.tar.gz: f9c4d0d31334b356185c149dd071cbaf32ad707675b63811e2ab751d044a89489c00756faa267cad363445af6bde95975538d06b4ae259535ebb96222bf5faea
6
+ metadata.gz: 42a65d8ce8ab998d31d367ef4f66b9baa0ea85151c00b729104bf631b4c6c1211f309185c728db938fbf3e960244c9ff80d95a019d689ffeaee0c0b43687b6cc
7
+ data.tar.gz: dae12374c57ec4984b0744886681925e87e79a21f7f6dbd662c1188d52584cd2ecf28f09e687df1826df4d6e2bf8bf7bb172860738c271200f2aab3f3efb7a5a
data/CHANGELOG.md CHANGED
@@ -11,6 +11,13 @@
11
11
  * Catch 500 or exceptions.
12
12
 
13
13
 
14
+ ## v0.1.2
15
+
16
+ ### Fixes
17
+
18
+ * Optimize the process of saving collected datas.
19
+ * Truncate table instead delete db file (#31).
20
+ * Small code cleanup.
14
21
 
15
22
 
16
23
  ## v0.1.1
@@ -34,7 +41,7 @@
34
41
 
35
42
  ### Fixes
36
43
 
37
- * Debug SQLite database stabilty by using a single thread.
44
+ * Debug SQLite database stabilty by using a single thread.
38
45
 
39
46
 
40
47
  ## v0.1.0.beta2
@@ -12,20 +12,10 @@ ICON
12
12
 
13
13
  collect do |request, _response|
14
14
  store :rack_version, Rack.release
15
- store :rack_env, hash_stringify_values(request.env)
15
+ store :rack_env, Rack::WebProfiler::Utils.hash_stringify_values(request.env)
16
16
  end
17
17
 
18
18
  template __FILE__, type: :DATA
19
-
20
- class << self
21
- def hash_stringify_values(hash)
22
- return {} unless hash.kind_of?(Hash)
23
- hash.collect do |k,v|
24
- v = v.inspect unless v.kind_of?(String)
25
- [k, v]
26
- end
27
- end
28
- end
29
19
  end
30
20
  end
31
21
 
@@ -17,7 +17,7 @@ ICON
17
17
  store :request_cookies, request.cookies
18
18
  store :request_get, request.GET
19
19
  store :request_post, request_post(request)
20
- store :request_session, hash_stringify_values(request.session)
20
+ store :request_session, Rack::WebProfiler::Utils.hash_stringify_values(request.session)
21
21
  store :request_cookies, request.cookies
22
22
  store :request_body, request.body_string
23
23
  store :request_mediatype, request.media_type
@@ -44,11 +44,6 @@ ICON
44
44
  rescue Exception
45
45
  nil
46
46
  end
47
-
48
- def hash_stringify_values(hash)
49
- return {} unless hash.kind_of?(Hash)
50
- hash.collect {|k,v| [k, v.to_s]}
51
- end
52
47
  end
53
48
  end
54
49
  end
@@ -1,4 +1,5 @@
1
1
  require "fileutils"
2
+ require "tmpdir"
2
3
 
3
4
  module Rack
4
5
  # Config
@@ -11,6 +12,8 @@ module Rack
11
12
  Rack::WebProfiler::Collectors::RubyCollector,
12
13
  Rack::WebProfiler::Collectors::TimeCollector,
13
14
  ].freeze
15
+
16
+ # Initialize Config.
14
17
  def initialize
15
18
  @collectors = Rack::WebProfiler::Collectors.new
16
19
 
@@ -73,40 +73,40 @@ module Rack
73
73
  attr_reader :record
74
74
 
75
75
  def initialize(request, response)
76
- @collectors = {}
77
- @request = request.clone.freeze
78
- @response = response.clone.freeze
79
- @record = nil
76
+ @record = new_record(request.clone.freeze, response.clone.freeze)
80
77
  end
81
78
 
82
79
  def save!
83
- create_record!
84
- save_collected_datas!
85
-
86
80
  @record.save({ transaction: true })
81
+ rescue => e
82
+ # @todo raise_if_debug WebProfiler::RuntimeError, "Error while processing to save datas", e.backtrace
87
83
  end
88
84
 
89
85
  private
90
86
 
91
- def create_record!
92
- @record ||= WebProfiler::Model::CollectionRecord.create({
93
- url: @request.url,
94
- ip: @request.ip,
95
- http_method: @request.request_method,
96
- http_status: @response.status,
97
- content_type: @response.content_type,
98
- datas: {},
87
+ def new_record(request, response)
88
+ WebProfiler::Model::CollectionRecord.new({
89
+ url: request.url,
90
+ ip: request.ip,
91
+ http_method: request.request_method,
92
+ http_status: response.status,
93
+ content_type: response.content_type,
94
+ datas: collect_datas(request, response),
99
95
  })
100
96
  end
101
97
 
102
- def save_collected_datas!
98
+ def collect_datas(request, response)
103
99
  datas = {}
104
100
 
105
101
  Rack::WebProfiler.config.collectors.all.each do |name, definition|
106
- datas[name.to_sym] = definition.collect!(@request, @response).to_h
102
+ begin
103
+ datas[name.to_sym] = definition.collect!(request, response).to_h
104
+ rescue => e
105
+ # @todo raise_if_debug WebProfiler::RuntimeError, "Error while collecting datas of collector '#{name}'"
106
+ end
107
107
  end
108
108
 
109
- @record.datas = datas
109
+ datas
110
110
  end
111
111
  end
112
112
  end
@@ -22,9 +22,7 @@ module Rack
22
22
  def clean!
23
23
  return unless ::File.exist?(db_file_path)
24
24
 
25
- ::File.delete(db_file_path)
26
- @db = nil
27
- @db_file_path = nil
25
+ CollectionRecord.truncate
28
26
  end
29
27
 
30
28
  private
@@ -0,0 +1,13 @@
1
+ module Rack
2
+ class WebProfiler::Utils
3
+ class << self
4
+ def hash_stringify_values(hash)
5
+ return {} unless hash.kind_of?(Hash)
6
+ hash.collect do |k,v|
7
+ v = v.inspect unless v.kind_of?(String)
8
+ [k, v]
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class WebProfiler
3
- VERSION = "0.1.1".freeze
3
+ VERSION = "0.1.2".freeze
4
4
  end
5
5
  end
@@ -13,6 +13,7 @@ module Rack
13
13
  autoload :Response, "rack/web_profiler/response"
14
14
  autoload :Request, "rack/web_profiler/request"
15
15
  autoload :Router, "rack/web_profiler/router"
16
+ autoload :Utils, "rack/web_profiler/utils"
16
17
  autoload :View, "rack/web_profiler/view"
17
18
 
18
19
  # Classes about Rouge gem customization.
@@ -20,6 +21,9 @@ module Rack
20
21
  autoload :HTMLFormatter, "rack/web_profiler/rouge/html_formatter"
21
22
  end
22
23
 
24
+ # Exceptions
25
+ class RuntimeError < ::RuntimeError; end
26
+
23
27
  # Env key constants.
24
28
  ENV_RUNTIME_START = "rack_webprofiler.runtime_start".freeze
25
29
  ENV_RUNTIME = "rack_webprofiler.runtime".freeze
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-webprofiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Brousse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-22 00:00:00.000000000 Z
11
+ date: 2017-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -168,6 +168,7 @@ files:
168
168
  - lib/rack/web_profiler/response.rb
169
169
  - lib/rack/web_profiler/rouge/html_formatter.rb
170
170
  - lib/rack/web_profiler/router.rb
171
+ - lib/rack/web_profiler/utils.rb
171
172
  - lib/rack/web_profiler/version.rb
172
173
  - lib/rack/web_profiler/view.rb
173
174
  - lib/rack/webprofiler.rb