coaster 1.3.2 → 1.3.6
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 +4 -4
- data/lib/coaster/core_ext.rb +1 -0
- data/lib/coaster/core_ext/require_more.rb +22 -0
- data/lib/coaster/core_ext/standard_error.rb +12 -18
- data/lib/coaster/version.rb +1 -1
- data/test/test_standard_error.rb +36 -12
- metadata +6 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b02f79c7d532c329c31d1a0447b62cc35fe42f53292504a3c23f1972716da2c3
|
|
4
|
+
data.tar.gz: 65adb3dcaff69b3dc0dce3a9ebd46da13477aef544ef22bfedd08cc2fa925f56
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c3943edf41f83c52e861b672e6c47ff6b3f5bd974195d4e8a492e11586c86b4c643dc52e24edbc5e15bc081453a243a1bd4148c4f029837c4d90417d4303a176
|
|
7
|
+
data.tar.gz: 555ef999a7d0fa9f3b0ecdcc416d70724af1801a049b86d5877d126236c70b097fea9701a36226e7c1cfea416cf8008bde81e5551a149ed7d0449d303e47ecc3
|
data/lib/coaster/core_ext.rb
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
def require_more
|
|
2
|
+
required_file_path = caller[0].split(':', 2).first
|
|
3
|
+
load_name = nil
|
|
4
|
+
load_path_index = $LOAD_PATH.each_with_index do |load_path, ix|
|
|
5
|
+
scanned = required_file_path.scan(/(#{load_path})#{File::SEPARATOR}(.*)/).first
|
|
6
|
+
next false unless scanned
|
|
7
|
+
load_name = scanned[1]
|
|
8
|
+
break ix
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
return false unless load_path_index
|
|
12
|
+
|
|
13
|
+
more_load_paths = $LOAD_PATH.drop(load_path_index + 1)
|
|
14
|
+
more_load_paths.each do |load_path|
|
|
15
|
+
path = File.join(load_path, load_name)
|
|
16
|
+
if File.exists?(path)
|
|
17
|
+
return require_dependency path
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
raise LoadError, "cannot require more -- #{load_name}"
|
|
22
|
+
end
|
|
@@ -53,6 +53,7 @@ class StandardError
|
|
|
53
53
|
msg = message
|
|
54
54
|
set_backtrace(message.backtrace)
|
|
55
55
|
when Hash then
|
|
56
|
+
@coaster = true # coaster 확장을 사용한 에러임을 확인할 수 있음.
|
|
56
57
|
hash = message.with_indifferent_access rescue message
|
|
57
58
|
msg = hash.delete(:m)
|
|
58
59
|
msg = hash.delete(:msg) || msg
|
|
@@ -63,6 +64,12 @@ class StandardError
|
|
|
63
64
|
@level = hash.delete(:level) || hash.delete(:severity) || @level
|
|
64
65
|
@tkey = hash.delete(:tkey)
|
|
65
66
|
@attributes.merge!(hash)
|
|
67
|
+
if @attributes[:description] == :translate
|
|
68
|
+
@attributes.delete(:description)
|
|
69
|
+
@attributes[:description] = _translate
|
|
70
|
+
end
|
|
71
|
+
msg = "#{_translate} (#{msg || self.class.name})"
|
|
72
|
+
msg = "#{msg} {#{cause.message}}" if cause
|
|
66
73
|
when String then
|
|
67
74
|
msg = message
|
|
68
75
|
when FalseClass, NilClass then
|
|
@@ -73,7 +80,7 @@ class StandardError
|
|
|
73
80
|
|
|
74
81
|
@fingerprint = [] unless @fingerprint.is_a?(Array)
|
|
75
82
|
@tags = {} unless @tags.is_a?(Hash)
|
|
76
|
-
msg = cause.message if msg.blank? && cause
|
|
83
|
+
msg = "{#{cause.message}}" if msg.blank? && cause
|
|
77
84
|
super(msg)
|
|
78
85
|
end
|
|
79
86
|
|
|
@@ -115,9 +122,7 @@ class StandardError
|
|
|
115
122
|
|
|
116
123
|
# description is user friendly message as a attribute, do not use error's message
|
|
117
124
|
# error message is not user friendly in many cases.
|
|
118
|
-
def description
|
|
119
|
-
attributes[:description] || attributes[:desc]
|
|
120
|
-
end
|
|
125
|
+
def description; attributes[:description] || attributes[:desc] end
|
|
121
126
|
alias_method :desc, :description
|
|
122
127
|
|
|
123
128
|
def _translate(*args)
|
|
@@ -131,10 +136,8 @@ class StandardError
|
|
|
131
136
|
|
|
132
137
|
# user friendly message, for overid
|
|
133
138
|
def user_message
|
|
134
|
-
return
|
|
135
|
-
|
|
136
|
-
return _translate
|
|
137
|
-
end
|
|
139
|
+
return _translate if description.present? || tkey.present?
|
|
140
|
+
return "#{_translate} (#{message})" unless defined?(@coaster)
|
|
138
141
|
message
|
|
139
142
|
end
|
|
140
143
|
|
|
@@ -145,15 +148,6 @@ class StandardError
|
|
|
145
148
|
attributes[:descriptions]
|
|
146
149
|
end
|
|
147
150
|
|
|
148
|
-
# https://github.com/getsentry/sentry-ruby/blob/fbbc7a51ed10684d0e8b7bd9d2a1b65a7351c9ef/lib/raven/event.rb#L162
|
|
149
|
-
# sentry message use `to_s` method
|
|
150
|
-
# https://ruby-doc.org/core-2.5.1/Exception.html#method-i-to_s
|
|
151
|
-
alias to_origin_s to_s
|
|
152
|
-
|
|
153
|
-
def to_s
|
|
154
|
-
"#{_translate} (#{to_origin_s})"
|
|
155
|
-
end
|
|
156
|
-
|
|
157
151
|
def to_hash
|
|
158
152
|
hash = attributes.merge(
|
|
159
153
|
type: self.class.name, status: status,
|
|
@@ -177,7 +171,7 @@ class StandardError
|
|
|
177
171
|
lg = "[#{self.class.name}] status:#{status}"
|
|
178
172
|
lg += "\n\tMESSAGE: #{safe_message.gsub(/\n/, "\n\t\t")}"
|
|
179
173
|
instance_variables.each do |var|
|
|
180
|
-
if var.to_s.start_with?('@_')
|
|
174
|
+
if var.to_s.start_with?('@_') || var.to_s == '@coaster'
|
|
181
175
|
next
|
|
182
176
|
elsif var.to_s == '@spell_checker'
|
|
183
177
|
next
|
data/lib/coaster/version.rb
CHANGED
data/test/test_standard_error.rb
CHANGED
|
@@ -22,8 +22,8 @@ module Coaster
|
|
|
22
22
|
|
|
23
23
|
def test_standard_messages
|
|
24
24
|
e = StandardError.new('developer message')
|
|
25
|
-
assert_equal "
|
|
26
|
-
assert_equal "
|
|
25
|
+
assert_equal "developer message", e.to_s
|
|
26
|
+
assert_equal "developer message", e.message
|
|
27
27
|
assert_nil e.description
|
|
28
28
|
assert_nil e.desc
|
|
29
29
|
assert_equal 'standard error translation', e._translate
|
|
@@ -41,8 +41,8 @@ module Coaster
|
|
|
41
41
|
|
|
42
42
|
def test_no_translation_class
|
|
43
43
|
e = UntitledError.new('developer message')
|
|
44
|
-
assert_equal "
|
|
45
|
-
assert_equal "
|
|
44
|
+
assert_equal "developer message", e.to_s
|
|
45
|
+
assert_equal "developer message", e.message
|
|
46
46
|
assert_nil e.description
|
|
47
47
|
assert_nil e.desc
|
|
48
48
|
assert_equal 'standard error translation', e._translate
|
|
@@ -68,8 +68,8 @@ module Coaster
|
|
|
68
68
|
|
|
69
69
|
def test_with_translation_class
|
|
70
70
|
e = SampleError.new
|
|
71
|
-
assert_equal "
|
|
72
|
-
assert_equal "
|
|
71
|
+
assert_equal "Coaster::TestStandardError::SampleError", e.to_s
|
|
72
|
+
assert_equal "Coaster::TestStandardError::SampleError", e.message
|
|
73
73
|
assert_nil e.description
|
|
74
74
|
assert_nil e.desc
|
|
75
75
|
assert_equal 'Test sample error', e._translate
|
|
@@ -84,13 +84,36 @@ module Coaster
|
|
|
84
84
|
assert_equal 'Test sample error (Coaster::TestStandardError::SampleError)', e.user_message
|
|
85
85
|
assert_equal 'Test this title', e.title
|
|
86
86
|
e = SampleError.new('developer message')
|
|
87
|
-
assert_equal "
|
|
88
|
-
assert_equal "
|
|
87
|
+
assert_equal "developer message", e.to_s
|
|
88
|
+
assert_equal "developer message", e.message
|
|
89
89
|
assert_nil e.description
|
|
90
90
|
assert_nil e.desc
|
|
91
91
|
assert_equal 'Test sample error', e._translate
|
|
92
92
|
assert_equal 'Test sample error (developer message)', e.user_message
|
|
93
93
|
assert_equal 'Test this title', e.title
|
|
94
|
+
e = SampleError.new(desc: 'user message')
|
|
95
|
+
assert_equal "user message (Coaster::TestStandardError::SampleError)", e.to_s
|
|
96
|
+
assert_equal "user message (Coaster::TestStandardError::SampleError)", e.message
|
|
97
|
+
assert_equal 'user message', e.description
|
|
98
|
+
assert_equal 'user message', e.desc
|
|
99
|
+
assert_equal 'user message', e._translate
|
|
100
|
+
assert_equal 'user message', e.user_message
|
|
101
|
+
assert_equal 'Test this title', e.title
|
|
102
|
+
e = SampleError.new(m: 'developer message', desc: :translate)
|
|
103
|
+
assert_equal "Test sample error (developer message)", e.to_s
|
|
104
|
+
assert_equal "Test sample error (developer message)", e.message
|
|
105
|
+
assert_equal "Test sample error", e.description
|
|
106
|
+
assert_equal "Test sample error", e.desc
|
|
107
|
+
assert_equal 'Test sample error', e._translate
|
|
108
|
+
assert_equal 'Test sample error', e.user_message
|
|
109
|
+
assert_equal 'Test this title', e.title
|
|
110
|
+
e = SampleError.new(desc: :translate)
|
|
111
|
+
assert_equal "Test sample error (Coaster::TestStandardError::SampleError)", e.to_s
|
|
112
|
+
assert_equal "Test sample error (Coaster::TestStandardError::SampleError)", e.message
|
|
113
|
+
assert_equal "Test sample error", e.description
|
|
114
|
+
assert_equal "Test sample error", e.desc
|
|
115
|
+
assert_equal "Test sample error", e._translate
|
|
116
|
+
assert_equal "Test sample error", e.user_message
|
|
94
117
|
e = SampleError.new(m: 'developer message', desc: 'user message')
|
|
95
118
|
assert_equal "user message (developer message)", e.to_s
|
|
96
119
|
assert_equal "user message (developer message)", e.message
|
|
@@ -132,7 +155,7 @@ module Coaster
|
|
|
132
155
|
assert_equal 'Coaster::TestStandardError::ExampleError', e.to_hash['type']
|
|
133
156
|
assert_equal 20, e.to_hash['status']
|
|
134
157
|
assert_equal 500, e.to_hash['http_status']
|
|
135
|
-
assert_equal "Test example error (Test sample error (
|
|
158
|
+
assert_equal "Test example error (Coaster::TestStandardError::ExampleError) {Test sample error (Coaster::TestStandardError::SampleError)}", e.to_hash['message']
|
|
136
159
|
assert_equal 'rams', e.to_hash['cause']['frog']
|
|
137
160
|
assert_equal 'Coaster::TestStandardError::SampleError', e.to_hash['cause']['type']
|
|
138
161
|
assert_equal 10, e.to_hash['cause']['status']
|
|
@@ -144,9 +167,10 @@ module Coaster
|
|
|
144
167
|
begin
|
|
145
168
|
raise SampleError, {frog: 'rams'}
|
|
146
169
|
rescue => e
|
|
147
|
-
raise ExampleError, {wat: 'cha'}
|
|
170
|
+
raise ExampleError, {m: 'abc', wat: 'cha'}
|
|
148
171
|
end
|
|
149
172
|
rescue => e
|
|
173
|
+
assert_equal 'Test example error (abc) {Test sample error (Coaster::TestStandardError::SampleError)}', e.message
|
|
150
174
|
assert_equal 'rams', e.cause.attr['frog']
|
|
151
175
|
assert_equal 'rams', e.attr['frog']
|
|
152
176
|
assert_equal 'cha', e.attr['wat']
|
|
@@ -161,7 +185,7 @@ module Coaster
|
|
|
161
185
|
rescue => e
|
|
162
186
|
detail = <<-LOG
|
|
163
187
|
[Coaster::TestStandardError::ExampleError] status:20
|
|
164
|
-
MESSAGE: Test example error (Test sample error (Coaster::TestStandardError::SampleError)
|
|
188
|
+
MESSAGE: Test example error (Coaster::TestStandardError::ExampleError) {Test sample error (Coaster::TestStandardError::SampleError)}
|
|
165
189
|
@fingerprint: []
|
|
166
190
|
@tags: {}
|
|
167
191
|
@level: \"error\"
|
|
@@ -218,7 +242,7 @@ LOG
|
|
|
218
242
|
begin
|
|
219
243
|
root_cause_sample3
|
|
220
244
|
rescue => e
|
|
221
|
-
assert_equal "
|
|
245
|
+
assert_equal "a", e.root_cause.message
|
|
222
246
|
end
|
|
223
247
|
end
|
|
224
248
|
|
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: 1.3.
|
|
4
|
+
version: 1.3.6
|
|
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: 2021-08-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: i18n
|
|
@@ -152,6 +152,7 @@ files:
|
|
|
152
152
|
- lib/coaster/core_ext/date.rb
|
|
153
153
|
- lib/coaster/core_ext/month.rb
|
|
154
154
|
- lib/coaster/core_ext/object_translation.rb
|
|
155
|
+
- lib/coaster/core_ext/require_more.rb
|
|
155
156
|
- lib/coaster/core_ext/standard_error.rb
|
|
156
157
|
- lib/coaster/core_ext/standard_error/raven.rb
|
|
157
158
|
- lib/coaster/serialized_properties.rb
|
|
@@ -179,12 +180,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
179
180
|
- !ruby/object:Gem::Version
|
|
180
181
|
version: '0'
|
|
181
182
|
requirements: []
|
|
182
|
-
rubygems_version: 3.
|
|
183
|
+
rubygems_version: 3.2.22
|
|
183
184
|
signing_key:
|
|
184
185
|
specification_version: 4
|
|
185
186
|
summary: A little convenient feature for standard library
|
|
186
187
|
test_files:
|
|
187
|
-
- test/
|
|
188
|
+
- test/locales/en.yml
|
|
188
189
|
- test/test_helper.rb
|
|
190
|
+
- test/test_object_translation.rb
|
|
189
191
|
- test/test_standard_error.rb
|
|
190
|
-
- test/locales/en.yml
|