lookout-rack-utils 3.3.0.22 → 3.3.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjFjZjM4ZTdlZTM0OTM4ZGI4ZGE0NTRlNTFiODlmYTQ4NzgxNjk0Nw==
4
+ YjBmOTI2MTc3YmEzMDlkN2U5ZDMxNjQyMjBiNWM3M2Y1ZTMxOGU5Yw==
5
5
  data.tar.gz: !binary |-
6
- MmU1MTc1YWYzOTljY2Y0ZTRhNjgyNTRhMTlhMmEyMmEyZDRlZmJmOQ==
6
+ MjQ1Mjc2YWQzMWUyZGRiNDFjMDdmZTQ4NDg0MWJlMjRkZTBjNGZhZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjQ1ZmJiYTI5ZDljYTczZDgwMTA3YjQ1NGNiNGY3YjA5OGIzNDhmMWExOTVj
10
- OWM3NDRiN2NjM2QxYmRlYTNhNGE3NzdjYmU5MjEzZTk5YmJkMzNlMjIwZTU3
11
- MWMwZDNiNjU3MjQ2OGNjNDBiMjUwYjAzZWY5MGUyNTAwNTYzNTM=
9
+ NzhhZmJhNDAwYzk1MzVmOTY2MjUyNjZmNWY4ZDNiODM0MmQxN2M4Mjk2Y2Uz
10
+ YzhmM2M2YTcwN2NjNGYzMDI4OGQyOTZlNzI2MzU3Y2FhYjUzMTk2N2RiNjRm
11
+ NjczMDY5YjllNzhiZDlmMDI0ZWM1OWFjM2E3M2U1MjBjM2EwOWY=
12
12
  data.tar.gz: !binary |-
13
- Y2UwOTVkMTM4YjMwODdhYzVmY2I2M2FlNDlmMTA4Yjc4NjBkYzgxOWI2M2Iw
14
- MGFjOGYwOWJhZTA1MTBmNGRjYTc4MzRiY2RmZDU3YjJhNmNlMjg1NTc1MTY5
15
- NWQxM2YwMjZjZDc2NDEzYTFjZTBkZTA1NmUyMGI2YWRkZjc0ODM=
13
+ NTk2MzVlNGE3MDZlZmUyOGNjMjAyNGRiMmI2Yjk4ZmM3OWY3NzIyZmVlMTFm
14
+ Y2I4ZjczYzY4MTg3MjQ4YTRjMTIwYWYzMGJiNWNkMmUxOGM1OTg1N2M3ZDlh
15
+ NjQxMTFiM2NkZGMxMTI5MmU1MWU1MGFmMGUzYjIyYWZiNDg4NGE=
data/.gitignore CHANGED
@@ -1,5 +1,7 @@
1
1
  *.gem
2
2
  *.rbc
3
+ .ruby-gemset
4
+ .ruby-version
3
5
  .bundle
4
6
  .config
5
7
  .yardoc
@@ -33,11 +33,36 @@ module Lookout::Rack::Utils
33
33
  @basedir ||= File.expand_path(File.join(File.dirname(__FILE__), ".."))
34
34
  end
35
35
 
36
+ # Return the common base directory between this project and the
37
+ # given trace. If no common base directory is found, return
38
+ # basedir.
39
+ #
40
+ # This memoizes the result, which can be bad if the first log
41
+ # comes from an unusual place. However, in all current uses this
42
+ # is running from an unpacked jar/war and its vastly faster to
43
+ # memoize the result.
44
+ #
45
+ # @param [String] tracer A line from the LogEvent#tracer Array
46
+ # @return [String] Common base directory with the trace
47
+ def common_basedir(tracer)
48
+ return @common_basedir if @common_basedir
49
+
50
+ basedir_pieces = basedir.split(File::SEPARATOR)
51
+ trace_pieces = tracer.split(File::SEPARATOR)
52
+ i = 0
53
+ while basedir_pieces[i] == trace_pieces[i]
54
+ i += 1
55
+ end
56
+ # If there were no common directories (besides /), return our basedir
57
+ @common_basedir = (i <= 1) ? basedir : basedir_pieces[0...i].join(File::SEPARATOR)
58
+ end
59
+
36
60
  # Return a trimmed version of the filename from where a LogEvent occurred
37
61
  # @param [String] tracer A line from the LogEvent#tracer Array
38
62
  # @return [String] Trimmed and parsed version of the file ane line number
39
63
  def event_filename(tracer)
40
- parts = tracer.match(/#{basedir}\/(.*:[0-9]+).*:/)
64
+ base = common_basedir(tracer)
65
+ parts = tracer.match(/#{base}\/(.*:[0-9]+).*:/)
41
66
 
42
67
  # If we get no matches back, we're probably in a jar file in which case
43
68
  # the format of the tracer is going to be abbreviated
data/spec/log_spec.rb CHANGED
@@ -158,4 +158,31 @@ describe Lookout::Rack::Utils::Log::LookoutFormatter do
158
158
  end
159
159
 
160
160
  end
161
+
162
+ describe "#common_basedir" do
163
+ subject(:common_basedir) { formatter.common_basedir(path) }
164
+
165
+ context "with no common path" do
166
+ let(:path) { "/impossible/path" }
167
+
168
+ it "should return basedir" do
169
+ expect(subject).to eq basedir
170
+ end
171
+ end
172
+
173
+ context "with a partially shared path" do
174
+ let(:path) { File.expand_path(File.join(basedir, "..", "tmp", "foo.rb")) }
175
+
176
+ it "should return shared path" do
177
+ expect(subject).to eq File.expand_path(File.join(basedir, ".."))
178
+ end
179
+ end
180
+
181
+ context "with a fully shared path" do
182
+ let(:path) { File.expand_path(File.join(basedir, "tmp.rb")) }
183
+ it "should return full path" do
184
+ expect(subject).to eq basedir
185
+ end
186
+ end
187
+ end
161
188
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lookout-rack-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0.22
4
+ version: 3.3.0.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-04 00:00:00.000000000 Z
11
+ date: 2016-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler