meta_request 0.7.0 → 0.7.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
  SHA256:
3
- metadata.gz: a4b9c5b68ec96706c97b7694930d494d51a71d4cdfe8d0e4a31a1c5a3bd6162b
4
- data.tar.gz: 12175a52caa80018ac03d1c47cce506da4f41094e72bbb36a3f950812436b2e5
3
+ metadata.gz: 49547952caa2d8244dc0342d0068ef44f2d8f2d5d98c6a6aa8ecac22df3e9122
4
+ data.tar.gz: d12d541968366874869350e81c716cb818966c6d3e897cb4081f8478b58bfb4a
5
5
  SHA512:
6
- metadata.gz: f4344ff68b5379c110ed0a6f1d4b9e852b8dc72b3f6c3e323bcf36fc6e62b4aef196d9f61b81f38922c1c577c48f763b0fe574a7db6183d28ef931e8746d02d5
7
- data.tar.gz: 5e3f37af2fb91197b442cb41f57f71c3c8aff600cfa6ce9ccf516419aa48f2e954ae7553b038c67b2bf7efbe647f34a794fd4afe2fb5554b7d53f4976b6a1bcb
6
+ metadata.gz: 37d7b6d8f7475c6e4774e8c98484e19076a462122cd1f9861bd32772e3a8effa758bb08a57d09816f3b56af49ebe26deae2cdd6ae6e3dc605fb2d57fe404cc56
7
+ data.tar.gz: 82ee0cd01dfcf01d4e5c8b276f2c9d899bdd2f0aa59e97fe1dcb5a0b4619aacb04d55ca3e28516d9ed364d4e9ef2c1babe2454a5e6aaa679d1e5435c931a12e9
data/README.md CHANGED
@@ -23,11 +23,23 @@ If you're using [LiveReload](http://livereload.com/) or
23
23
  exclude watching your tmp/ folder because meta_request writes a lot of data there
24
24
  and your browser will refresh like a madman.
25
25
 
26
+ ## Configuration
27
+
28
+ Gem can be configured using block:
29
+
30
+ ```ruby
31
+ MetaRequest.configure do |config|
32
+ config.storage_pool_size = 30
33
+ end
34
+ ```
35
+
36
+ List of available attributes and defaults can be found in [lib/meta_request/config.rb](lib/meta_request/config.rb).
37
+
26
38
  ## Development
27
39
 
28
- Run tests:
40
+ Run all tests:
29
41
 
30
- make
42
+ docker-compose up
31
43
 
32
44
  ## Licence
33
45
 
data/lib/meta_request.rb CHANGED
@@ -1,20 +1,26 @@
1
1
  module MetaRequest
2
2
  autoload :VERSION, "meta_request/version"
3
+ autoload :Config, "meta_request/config"
3
4
  autoload :Event, "meta_request/event"
4
5
  autoload :AppRequest, "meta_request/app_request"
5
6
  autoload :Storage, "meta_request/storage"
6
7
  autoload :Middlewares, "meta_request/middlewares"
7
8
  autoload :LogInterceptor, "meta_request/log_interceptor"
8
9
  autoload :AppNotifications, "meta_request/app_notifications"
10
+ autoload :Utils, "meta_request/utils"
9
11
 
10
- def self.logger
11
- @@logger ||= Logger.new(File.join(Rails.root, 'log', 'meta_request.log'))
12
+ def self.config
13
+ @config ||= Config.new
14
+ end
15
+
16
+ def self.configure
17
+ yield config
12
18
  end
13
19
 
14
20
  # stash a frozen copy away so we're not allocating a new string over and over
15
21
  # again in AppNotifications and LogInterceptor
16
22
  def self.rails_root
17
- @@rails_root ||= Rails.root.to_s.freeze
23
+ @rails_root ||= Rails.root.to_s.freeze
18
24
  end
19
25
  end
20
26
 
@@ -24,10 +24,10 @@ module MetaRequest
24
24
  payload[:options][k] = payload.delete(k) unless k.in? CACHE_KEY_COLUMNS
25
25
  end
26
26
 
27
- dev_caller = caller.detect { |c| c.include? MetaRequest.rails_root }
28
- if dev_caller
29
- c = Callsite.parse(dev_caller)
30
- payload.merge!(:line => c.line, :filename => c.filename, :method => c.method)
27
+ dev_callsite = Utils.dev_callsite(caller)
28
+
29
+ if dev_callsite
30
+ payload.merge!(:line => dev_callsite.line, :filename => dev_callsite.filename, :method => dev_callsite.method)
31
31
  end
32
32
 
33
33
  Event.new(name, start, ending, transaction_id, payload)
@@ -43,11 +43,12 @@ module MetaRequest
43
43
 
44
44
  SQL_BLOCK = Proc.new {|*args|
45
45
  name, start, ending, transaction_id, payload = args
46
- dev_caller = caller.detect { |c| c.include? MetaRequest.rails_root }
47
- if dev_caller
48
- c = Callsite.parse(dev_caller)
49
- payload.merge!(:line => c.line, :filename => c.filename, :method => c.method)
46
+ dev_callsite = Utils.dev_callsite(caller)
47
+
48
+ if dev_callsite
49
+ payload.merge!(:line => dev_callsite.line, :filename => dev_callsite.filename, :method => dev_callsite.method)
50
50
  end
51
+
51
52
  Event.new(SQL_EVENT_NAME, start, ending, transaction_id, payload)
52
53
  }
53
54
  # Subscribe to all events relevant to RailsPanel
@@ -0,0 +1,16 @@
1
+ module MetaRequest
2
+ class Config
3
+ attr_writer :logger, :storage_pool_size
4
+
5
+ # logger used for reporting gem's fatal errors
6
+ def logger
7
+ @logger ||= Logger.new(File.join(Rails.root, 'log', 'meta_request.log'))
8
+ end
9
+
10
+ # Number of files kept in storage.
11
+ # Increase when using an application loading many simultaneous requests.
12
+ def storage_pool_size
13
+ @storage_pool_size ||= 20
14
+ end
15
+ end
16
+ end
@@ -38,7 +38,7 @@ module MetaRequest
38
38
  transform_hash(payload, :deep => true) { |hash, key, value|
39
39
  if value.class.to_s == 'ActionDispatch::Http::Headers'
40
40
  value = value.to_h.select { |k, _| k.upcase == k }
41
- elsif value.is_a?(ActiveRecord::ConnectionAdapters::AbstractAdapter)
41
+ elsif defined?(ActiveRecord) && value.is_a?(ActiveRecord::ConnectionAdapters::AbstractAdapter)
42
42
  value = NOT_JSON_ENCODABLE
43
43
  end
44
44
 
@@ -1,5 +1,3 @@
1
- require 'callsite'
2
-
3
1
  module MetaRequest
4
2
  module LogInterceptor
5
3
 
@@ -36,14 +34,13 @@ module MetaRequest
36
34
 
37
35
  private
38
36
  def push_event(level, message)
39
- dev_log = AppRequest.current && caller[1].include?(MetaRequest.rails_root)
40
- if dev_log
41
- c = Callsite.parse(caller[1])
42
- payload = {:message => message, :level => level, :line => c.line, :filename => c.filename, :method => c.method}
37
+ dev_callsite = AppRequest.current && Utils.dev_callsite(caller[1])
38
+ if dev_callsite
39
+ payload = {:message => message, :level => level, :line => dev_callsite.line, :filename => dev_callsite.filename, :method => dev_callsite.method}
43
40
  AppRequest.current.events << Event.new('meta_request.log', 0, 0, 0, payload)
44
41
  end
45
42
  rescue Exception => e
46
- MetaRequest.logger.fatal(e.message + "\n " + e.backtrace.join("\n "))
43
+ MetaRequest.config.logger.fatal(e.message + "\n " + e.backtrace.join("\n "))
47
44
  end
48
45
  end
49
46
  end
@@ -9,7 +9,7 @@ module MetaRequest
9
9
  def write(value)
10
10
  FileUtils.mkdir_p dir_path
11
11
  File.open(json_file, 'wb') { |file| file.write(value) }
12
- maintain_file_pool(10)
12
+ maintain_file_pool(MetaRequest.config.storage_pool_size)
13
13
  end
14
14
 
15
15
  def read
@@ -27,7 +27,7 @@ module MetaRequest
27
27
  end
28
28
 
29
29
  def file_ctime(file)
30
- File.stat(file).ctime.to_i
30
+ File.stat(file).ctime.to_i
31
31
  rescue Errno::ENOENT
32
32
  0
33
33
  end
@@ -0,0 +1,13 @@
1
+ require 'callsite'
2
+
3
+ module MetaRequest
4
+ module Utils
5
+ extend self
6
+
7
+ # @return [Callsite::Line, nil]
8
+ def dev_callsite(caller)
9
+ app_line = Array(caller).detect { |c| c.start_with? MetaRequest.rails_root }
10
+ Callsite.parse(app_line) if app_line
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module MetaRequest
2
- VERSION = '0.7.0'
2
+ VERSION = Gem.loaded_specs["meta_request"].version.to_s
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meta_request
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dejan Simic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-28 00:00:00.000000000 Z
11
+ date: 2019-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -80,6 +80,7 @@ files:
80
80
  - lib/meta_request.rb
81
81
  - lib/meta_request/app_notifications.rb
82
82
  - lib/meta_request/app_request.rb
83
+ - lib/meta_request/config.rb
83
84
  - lib/meta_request/event.rb
84
85
  - lib/meta_request/log_interceptor.rb
85
86
  - lib/meta_request/middlewares.rb
@@ -88,6 +89,7 @@ files:
88
89
  - lib/meta_request/middlewares/meta_request_handler.rb
89
90
  - lib/meta_request/railtie.rb
90
91
  - lib/meta_request/storage.rb
92
+ - lib/meta_request/utils.rb
91
93
  - lib/meta_request/version.rb
92
94
  homepage: https://github.com/dejan/rails_panel/tree/master/meta_request
93
95
  licenses:
@@ -108,8 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
110
  - !ruby/object:Gem::Version
109
111
  version: '0'
110
112
  requirements: []
111
- rubyforge_project:
112
- rubygems_version: 2.7.8
113
+ rubygems_version: 3.0.3
113
114
  signing_key:
114
115
  specification_version: 4
115
116
  summary: Request your Rails request