scrolls 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/scrolls/log.rb CHANGED
@@ -101,8 +101,7 @@ module Scrolls
101
101
  :exception_id => e.object_id.abs
102
102
  ))
103
103
  if e.backtrace
104
- bt = e.backtrace.reverse
105
- bt[0, bt.size-6].each do |line|
104
+ e.backtrace.each do |line|
106
105
  log(logdata.merge(
107
106
  :at => "exception",
108
107
  :class => e.message,
@@ -118,6 +117,7 @@ module Scrolls
118
117
  old = context
119
118
  self.context = old.merge(prefix)
120
119
  res = yield if block_given?
120
+ ensure
121
121
  self.context = old
122
122
  res
123
123
  end
@@ -14,10 +14,19 @@ module Scrolls
14
14
  "#{k}=nil"
15
15
  elsif v.is_a?(Time)
16
16
  "#{k}=#{Time.at(v).strftime("%FT%H:%M:%S%z")}"
17
- elsif v.is_a?(String) && v =~ /\\|\"| /
18
- v = v.gsub(/\\|"/) { |c| "\\#{c}" }
19
- "#{k}=\"#{v}\""
20
17
  else
18
+ v = v.to_s
19
+ has_single_quote = v.index("'")
20
+ has_double_quote = v.index('"')
21
+ if v =~ / /
22
+ if has_single_quote && has_double_quote
23
+ v = '"' + v.gsub(/\\|"/) { |c| "\\#{c}" } + '"'
24
+ elsif has_double_quote
25
+ v = "'" + v.gsub('\\', '\\\\\\') + "'"
26
+ else
27
+ v = '"' + v.gsub('\\', '\\\\\\') + '"'
28
+ end
29
+ end
21
30
  "#{k}=#{v}"
22
31
  end
23
32
  end.compact.join(" ")
@@ -28,8 +37,9 @@ module Scrolls
28
37
  str = data.dup if data.is_a?(String)
29
38
 
30
39
  patterns = [
31
- /([^= ]+)="([^"\\]*(\\.[^"\\]*)*)"/, # key="\"literal\" escaped val"
32
- /([^= ]+)=([^ =]+)/ # key=value
40
+ /([^= ]+)="((?:\\.|[^"\\])*)"/, # key="\"literal\" escaped val"
41
+ /([^= ]+)='((?:\\.|[^'\\])*)'/, # key='\'literal\' escaped val'
42
+ /([^= ]+)=([^ =]+)/ # key=value
33
43
  ]
34
44
 
35
45
  patterns.each do |pattern|
@@ -1,3 +1,3 @@
1
1
  module Scrolls
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
data/test/test_parser.rb CHANGED
@@ -21,12 +21,16 @@ class TestScrollsParser < Test::Unit::TestCase
21
21
  assert_equal 's="echo \'hello\' \\"world\\""', unparse(data)
22
22
  assert_equal data.inspect, parse(unparse(data)).inspect
23
23
 
24
+ data = { s: 'echo "hello"' }
25
+ assert_equal "s='echo \"hello\"'", unparse(data)
26
+ assert_equal data.inspect, parse(unparse(data)).inspect
27
+
24
28
  data = { s: "hello world" }
25
29
  assert_equal 's="hello world"', unparse(data)
26
30
  assert_equal data.inspect, parse(unparse(data)).inspect
27
31
 
28
- data = { s: "slasher\\" }
29
- assert_equal 's="slasher\\\\"', unparse(data)
32
+ data = { s: "slasher \\" }
33
+ assert_equal 's="slasher \\\\"', unparse(data)
30
34
  assert_equal data.inspect, parse(unparse(data)).inspect
31
35
 
32
36
  # simple value is unquoted
data/test/test_scrolls.rb CHANGED
@@ -72,6 +72,18 @@ class TestScrolls < Test::Unit::TestCase
72
72
  assert_equal output, @out.string
73
73
  end
74
74
 
75
+ def test_context_after_exception
76
+ begin
77
+ Scrolls.context(c: 'c') do
78
+ raise "Error from inside of context"
79
+ end
80
+ fail "Exception did not escape context block"
81
+ rescue => e
82
+ Scrolls.log(o: 'o')
83
+ assert_equal "o=o\n", @out.string
84
+ end
85
+ end
86
+
75
87
  def test_default_time_unit
76
88
  assert_equal "seconds", Scrolls.time_unit
77
89
  end
@@ -104,7 +116,10 @@ class TestScrolls < Test::Unit::TestCase
104
116
  rescue Exception => e
105
117
  Scrolls.log_exception({test: "exception"}, e)
106
118
  end
107
- @out.truncate(27)
108
- assert_equal "test=exception at=exception", @out.string
119
+
120
+ oneline_backtrace = @out.string.gsub("\n", 'XX')
121
+
122
+ assert_match /test=exception at=exception.*test_log_exception.*XX.*minitest/,
123
+ oneline_backtrace
109
124
  end
110
125
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrolls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-02 00:00:00.000000000 Z
12
+ date: 2013-04-27 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Logging, easier, more consistent.
15
15
  email: