coaster 0.5.8 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/coaster/core_ext/object_translation.rb +4 -3
- data/lib/coaster/core_ext/standard_error.rb +30 -29
- data/lib/coaster/version.rb +1 -1
- data/test/locales/en.yml +4 -0
- data/test/test_object_translation.rb +4 -0
- data/test/test_standard_error.rb +19 -20
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bb245ac61cf472e066e9f33934edfb00b715b07a2745ba30dcee503d973fbee
|
4
|
+
data.tar.gz: 133b5ae2c21130ff0b9ed27d03388b5f682b7ff95f31c2c455f2a36b62084cf4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c26dfe88f571581a60fac9c5f7a4594ce6929e7dbee7aab4bd3b134e29e595ab8f3ee2dd912110625a810deef1bf5ef0c67e8935c4b9d9a5e1fd459a8a23b2ca
|
7
|
+
data.tar.gz: 983374e824e12b9da051ec0a246e65a6aaa0fe35c1bb75561aaff3398f4ffcd9f63009b6db97f23ff163ba073563400be07368103f9595b28049e489a7f39e3c
|
@@ -3,8 +3,9 @@ require 'i18n'
|
|
3
3
|
class Object
|
4
4
|
class << self
|
5
5
|
def _translate(*args)
|
6
|
-
options = args.last.is_a?(Hash) ? args.pop
|
6
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
7
7
|
options.merge!(_translate_params)
|
8
|
+
options = options.to_hash.symbolize_keys!
|
8
9
|
|
9
10
|
key = args.shift
|
10
11
|
subkey = nil
|
@@ -33,7 +34,6 @@ class Object
|
|
33
34
|
end
|
34
35
|
options[:tkey] ||= key
|
35
36
|
options.merge!(throw: true)
|
36
|
-
options.symbolize_keys!
|
37
37
|
result = catch(:exception) do
|
38
38
|
I18n.t(key, *args, options)
|
39
39
|
end
|
@@ -58,6 +58,7 @@ class Object
|
|
58
58
|
_translate(subkey, *args, options)
|
59
59
|
end
|
60
60
|
else
|
61
|
+
result = result.dup if result.frozen?
|
61
62
|
result.instance_variable_set(:@translated, true)
|
62
63
|
result.instance_variable_set(:@tkey, options[:tkey])
|
63
64
|
result
|
@@ -75,7 +76,7 @@ class Object
|
|
75
76
|
# Foo::Bar.new._translate(:force) #=> ignore 'message' even if message exists
|
76
77
|
#
|
77
78
|
def _translate(*args)
|
78
|
-
options = args.last.is_a?(Hash) ? args.pop
|
79
|
+
options = (args.last.is_a?(Hash) ? args.pop : {}).with_indifferent_access
|
79
80
|
key = args.shift || (respond_to?(:tkey) ? tkey : nil)
|
80
81
|
|
81
82
|
if respond_to?(:description) && description.present? && description != 'false' && description != self.class.name
|
@@ -26,42 +26,43 @@ class StandardError
|
|
26
26
|
@tags = {}
|
27
27
|
@level = 'error'
|
28
28
|
@attributes = HashWithIndifferentAccess.new
|
29
|
+
@attributes.merge!(cause.attributes || {}) if cause && cause.respond_to?(:attributes)
|
29
30
|
@tkey = nil
|
30
31
|
|
31
32
|
case message
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
33
|
+
when Exception
|
34
|
+
msg = message
|
35
|
+
set_backtrace(message.backtrace)
|
36
|
+
when StandardError
|
37
|
+
@fingerprint = message.fingerprint
|
38
|
+
@tags = message.tags
|
39
|
+
@level = message.level
|
40
|
+
@tkey = message.tkey
|
41
|
+
@attributes = message.attributes
|
42
|
+
msg = message
|
43
|
+
set_backtrace(message.backtrace)
|
44
|
+
when Hash then
|
45
|
+
hash = message.with_indifferent_access rescue message
|
46
|
+
msg = hash.delete(:m)
|
47
|
+
msg = hash.delete(:msg) || msg
|
48
|
+
msg = hash.delete(:message) || msg
|
49
|
+
@fingerprint = hash.delete(:fingerprint) || hash.delete(:fingerprints)
|
50
|
+
@tags = hash.delete(:tags) || hash.delete(:tag)
|
51
|
+
@level = hash.delete(:level) || hash.delete(:severity) || @level
|
52
|
+
@tkey = hash.delete(:tkey)
|
53
|
+
msg = cause.message if msg.nil? && cause
|
54
|
+
@attributes.merge!(hash)
|
55
|
+
when String then
|
56
|
+
msg = message
|
57
|
+
when FalseClass, NilClass then
|
58
|
+
msg = ''
|
59
|
+
else
|
60
|
+
msg = message
|
60
61
|
end
|
61
62
|
|
62
63
|
@fingerprint = [] unless @fingerprint.is_a?(Array)
|
63
64
|
@tags = {} unless @tags.is_a?(Hash)
|
64
|
-
msg ||= self.class.
|
65
|
+
msg ||= self.class._translate
|
65
66
|
super(msg)
|
66
67
|
end
|
67
68
|
|
data/lib/coaster/version.rb
CHANGED
data/test/locales/en.yml
CHANGED
@@ -5,8 +5,12 @@ en:
|
|
5
5
|
SampleObject:
|
6
6
|
self: 'Coaster SampleObject Translated'
|
7
7
|
title: 'Coaster SampleObject Title (%{tkey})'
|
8
|
+
interpolation: 'Coaster SampleObject interpolation test %{test_this}'
|
8
9
|
TestStandardError:
|
10
|
+
ExampleError:
|
11
|
+
self: 'Test example error'
|
9
12
|
SampleError:
|
13
|
+
self: 'Test sample error'
|
10
14
|
test: 'Test this translation'
|
11
15
|
title: 'Test this title'
|
12
16
|
sample:
|
@@ -48,6 +48,10 @@ module Coaster
|
|
48
48
|
assert_equal 'Coaster SampleObject Title (class.Coaster.Inherited.title)', Inherited._translate(:title)
|
49
49
|
end
|
50
50
|
|
51
|
+
def test_interpolation
|
52
|
+
assert_equal 'Coaster SampleObject interpolation test this interpolated', SampleObject._translate('.interpolation', {test_this: 'this interpolated'}.with_indifferent_access)
|
53
|
+
end
|
54
|
+
|
51
55
|
def teardown
|
52
56
|
I18n.locale = nil
|
53
57
|
I18n.default_locale = nil
|
data/test/test_standard_error.rb
CHANGED
@@ -39,20 +39,16 @@ module Coaster
|
|
39
39
|
raise ExampleError, {wat: 'cha'}
|
40
40
|
end
|
41
41
|
rescue => e
|
42
|
-
assert_equal
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
"http_status"=>500,
|
53
|
-
"message"=>"Test this title"
|
54
|
-
}
|
55
|
-
}, e.to_hash)
|
42
|
+
assert_equal e.to_hash['wat'], 'cha'
|
43
|
+
assert_equal e.to_hash['type'], 'Coaster::TestStandardError::ExampleError'
|
44
|
+
assert_equal e.to_hash['status'], 20
|
45
|
+
assert_equal e.to_hash['http_status'], 500
|
46
|
+
assert_equal e.to_hash['message'], 'Test sample error'
|
47
|
+
assert_equal e.to_hash['cause']['frog'], 'rams'
|
48
|
+
assert_equal e.to_hash['cause']['type'], 'Coaster::TestStandardError::SampleError'
|
49
|
+
assert_equal e.to_hash['cause']['status'], 10
|
50
|
+
assert_equal e.to_hash['cause']['http_status'], 500
|
51
|
+
assert_equal e.to_hash['cause']['message'], 'Test sample error'
|
56
52
|
end
|
57
53
|
|
58
54
|
def test_cause_attributes
|
@@ -62,7 +58,9 @@ module Coaster
|
|
62
58
|
raise ExampleError, {wat: 'cha'}
|
63
59
|
end
|
64
60
|
rescue => e
|
65
|
-
assert_equal
|
61
|
+
assert_equal e.cause.attr['frog'], 'rams'
|
62
|
+
assert_equal e.attr['frog'], 'rams'
|
63
|
+
assert_equal e.attr['wat'], 'cha'
|
66
64
|
end
|
67
65
|
|
68
66
|
def test_to_detail
|
@@ -74,15 +72,15 @@ module Coaster
|
|
74
72
|
rescue => e
|
75
73
|
detail = <<-LOG
|
76
74
|
[Coaster::TestStandardError::ExampleError] status:20
|
77
|
-
MESSAGE: Test
|
75
|
+
MESSAGE: Test sample error
|
78
76
|
@fingerprint: []
|
79
77
|
@tags: {}
|
80
78
|
@level: \"error\"
|
81
|
-
@attributes: {\"wat\"=>\"cha\"}
|
79
|
+
@attributes: {\"frog\"=>\"rams\", \"wat\"=>\"cha\"}
|
82
80
|
@tkey: nil
|
83
81
|
@raven: {}
|
84
82
|
CAUSE: [Coaster::TestStandardError::SampleError] status:10
|
85
|
-
MESSAGE: Test
|
83
|
+
MESSAGE: Test sample error
|
86
84
|
@fingerprint: []
|
87
85
|
@tags: {}
|
88
86
|
@level: \"error\"
|
@@ -108,7 +106,7 @@ LOG
|
|
108
106
|
def test_title_missing
|
109
107
|
raise UntitledError, 'untitled'
|
110
108
|
rescue => e
|
111
|
-
|
109
|
+
assert_nil e.title
|
112
110
|
end
|
113
111
|
|
114
112
|
def root_cause_sample1
|
@@ -138,7 +136,8 @@ LOG
|
|
138
136
|
def test_raven_notes
|
139
137
|
raise SampleError, m: 'foofoo', something: 'other'
|
140
138
|
rescue => e
|
141
|
-
assert_equal e.notes(the_other: 'something')
|
139
|
+
assert_equal e.notes(the_other: 'something')[:extra][:something], 'other'
|
140
|
+
assert_equal e.notes(the_other: 'something')[:extra][:the_other], 'something'
|
142
141
|
end
|
143
142
|
end
|
144
143
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coaster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- buzz jung
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|