meta_request 0.7.0 → 0.7.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
  SHA256:
3
- metadata.gz: a4b9c5b68ec96706c97b7694930d494d51a71d4cdfe8d0e4a31a1c5a3bd6162b
4
- data.tar.gz: 12175a52caa80018ac03d1c47cce506da4f41094e72bbb36a3f950812436b2e5
3
+ metadata.gz: 40d50e7981aca25dd87449d817b7a6e223491be3cb2155ad3ee82e081afce02f
4
+ data.tar.gz: 8fa75570b5c5b41b546f71aa883bd9df3bdf9b76e4a6a38f5498aa3af641e0fd
5
5
  SHA512:
6
- metadata.gz: f4344ff68b5379c110ed0a6f1d4b9e852b8dc72b3f6c3e323bcf36fc6e62b4aef196d9f61b81f38922c1c577c48f763b0fe574a7db6183d28ef931e8746d02d5
7
- data.tar.gz: 5e3f37af2fb91197b442cb41f57f71c3c8aff600cfa6ce9ccf516419aa48f2e954ae7553b038c67b2bf7efbe647f34a794fd4afe2fb5554b7d53f4976b6a1bcb
6
+ metadata.gz: 22764f1ec9e723a596e56993c802e541263ce1c7902b88c30902d69701a4b47705c404ce85fd3d2240f5fda7f5d1e85f0512f192647d181e10f30a5f13c6e6a0
7
+ data.tar.gz: 4c62d0983519f5ae3779759aeba06354e6cb9d4c920feb42f9966be91d0615ca8439c7749109435c3d916f1a40d3718b7c9c5dc99d88b50a04ee44b243b74374
data/README.md CHANGED
@@ -23,11 +23,35 @@ 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
+
38
+ ## Docker
39
+
40
+ Apps runing in Docker container will have filepaths of the container so links to editor would not work. To fix this, you need to propagate working directory through enviroment variable `SOURCE_PATH`. With docker-compose it can be done like this:
41
+
42
+ ```yaml
43
+ services:
44
+ app:
45
+ environment:
46
+ - SOURCE_PATH=$PWD
47
+ # ...
48
+ ```
49
+
26
50
  ## Development
27
51
 
28
- Run tests:
52
+ Run all tests:
29
53
 
30
- make
54
+ docker-compose up
31
55
 
32
56
  ## Licence
33
57
 
@@ -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,11 +24,8 @@ 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)
31
- end
27
+ callsite = Utils.dev_callsite(caller)
28
+ payload.merge!(callsite) if callsite
32
29
 
33
30
  Event.new(name, start, ending, transaction_id, payload)
34
31
  }
@@ -43,13 +40,19 @@ module MetaRequest
43
40
 
44
41
  SQL_BLOCK = Proc.new {|*args|
45
42
  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)
50
- end
43
+ callsite = Utils.dev_callsite(caller)
44
+ payload.merge!(callsite) if callsite
45
+
51
46
  Event.new(SQL_EVENT_NAME, start, ending, transaction_id, payload)
52
47
  }
48
+
49
+ VIEW_BLOCK = Proc.new {|*args|
50
+ name, start, ending, transaction_id, payload = args
51
+ payload[:identifier] = MetaRequest::Utils.sub_source_path(payload[:identifier])
52
+
53
+ Event.new(name, start, ending, transaction_id, payload)
54
+ }
55
+
53
56
  # Subscribe to all events relevant to RailsPanel
54
57
  #
55
58
  def self.subscribe
@@ -57,8 +60,8 @@ module MetaRequest
57
60
  subscribe("meta_request.log").
58
61
  subscribe("sql.active_record", &SQL_BLOCK).
59
62
  subscribe("sql.sequel", &SQL_BLOCK).
60
- subscribe("render_partial.action_view").
61
- subscribe("render_template.action_view").
63
+ subscribe("render_partial.action_view", &VIEW_BLOCK).
64
+ subscribe("render_template.action_view", &VIEW_BLOCK).
62
65
  subscribe("process_action.action_controller.exception").
63
66
  subscribe("process_action.action_controller") do |*args|
64
67
  name, start, ending, transaction_id, payload = args
@@ -0,0 +1,20 @@
1
+ module MetaRequest
2
+ class Config
3
+ attr_writer :logger, :storage_pool_size, :source_path
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
+
16
+ def source_path
17
+ @source_path ||= ENV['SOURCE_PATH'] || Rails.root.to_s
18
+ end
19
+ end
20
+ 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
 
@@ -33,17 +31,15 @@ module MetaRequest
33
31
  super
34
32
  end
35
33
 
36
-
37
34
  private
38
35
  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}
36
+ callsite = AppRequest.current && Utils.dev_callsite(caller.drop(1))
37
+ if callsite
38
+ payload = callsite.merge(message: message, level: level)
43
39
  AppRequest.current.events << Event.new('meta_request.log', 0, 0, 0, payload)
44
40
  end
45
41
  rescue Exception => e
46
- MetaRequest.logger.fatal(e.message + "\n " + e.backtrace.join("\n "))
42
+ MetaRequest.config.logger.fatal(e.message + "\n " + e.backtrace.join("\n "))
47
43
  end
48
44
  end
49
45
  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,25 @@
1
+ module MetaRequest
2
+ module Utils
3
+ extend self
4
+
5
+ def dev_callsite(caller)
6
+ app_line = caller.detect { |c| c.start_with? MetaRequest.rails_root }
7
+ return nil unless app_line
8
+
9
+ _, filename, _, line, _, method = app_line.split(/^(.*?)(:(\d+))(:in `(.*)')?$/)
10
+
11
+ {
12
+ filename: sub_source_path(filename),
13
+ line: line.to_i,
14
+ method: method
15
+ }
16
+ end
17
+
18
+ def sub_source_path(path)
19
+ rails_root = MetaRequest.rails_root
20
+ source_path = MetaRequest.config.source_path
21
+ return path if rails_root == source_path
22
+ path.sub(rails_root, source_path)
23
+ end
24
+ end
25
+ 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.2
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-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -50,26 +50,6 @@ dependencies:
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '3'
53
- - !ruby/object:Gem::Dependency
54
- name: callsite
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '0.0'
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 0.0.11
63
- type: :runtime
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '0.0'
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: 0.0.11
73
53
  description: Supporting gem for Rails Panel (Google Chrome extension for Rails development)
74
54
  email: desimic@gmail.com
75
55
  executables: []
@@ -80,6 +60,7 @@ files:
80
60
  - lib/meta_request.rb
81
61
  - lib/meta_request/app_notifications.rb
82
62
  - lib/meta_request/app_request.rb
63
+ - lib/meta_request/config.rb
83
64
  - lib/meta_request/event.rb
84
65
  - lib/meta_request/log_interceptor.rb
85
66
  - lib/meta_request/middlewares.rb
@@ -88,6 +69,7 @@ files:
88
69
  - lib/meta_request/middlewares/meta_request_handler.rb
89
70
  - lib/meta_request/railtie.rb
90
71
  - lib/meta_request/storage.rb
72
+ - lib/meta_request/utils.rb
91
73
  - lib/meta_request/version.rb
92
74
  homepage: https://github.com/dejan/rails_panel/tree/master/meta_request
93
75
  licenses:
@@ -108,8 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
90
  - !ruby/object:Gem::Version
109
91
  version: '0'
110
92
  requirements: []
111
- rubyforge_project:
112
- rubygems_version: 2.7.8
93
+ rubygems_version: 3.0.3
113
94
  signing_key:
114
95
  specification_version: 4
115
96
  summary: Request your Rails request