coaster 1.3.13 → 1.3.16

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: f0e72ea3485bb3e0fe4cf4a1ba46a8b9d15121f88451b616f7135a79b6c69513
4
- data.tar.gz: 4ea2ff71f70966987d41ee298b06d2b98d94888faf765eb55860a3bc99d042c0
3
+ metadata.gz: 9f77d0070583968f901f013740db84265ea28fcebddddf30dbc11dd441910563
4
+ data.tar.gz: aad9339285e5ae4e7fba33343b30b976f38f01454a586dd6d3577c9b7a17699b
5
5
  SHA512:
6
- metadata.gz: 5395ecbe606496812df91dd98fc79ac6917cc0f89bf85bc3e269deeff9a1316ac562a6273e64f403f85c8fd8a865b3b6307bb9764cc6ba8704cb9908f346cb59
7
- data.tar.gz: ae9094a1c819b49a356014c5bcc218291f4ecbb15e0670d3aaf6af88c4e52a19d2eac0b420118260927268fe01a593fb21e4f383395c0800b70b68cc0d42169b
6
+ metadata.gz: 36c410d67d869ee45be7441edb48943dd2d5e1f58d460071ec9ddcb9141bfee9958f9122ab9f7c003989052065834ea3a0bb0429876f66b989be2c598a96291d
7
+ data.tar.gz: 1bbba2dcad11976f9c9a088e9e46fd006512758cb53a01a21fdc0995233929428d491595bafca10f13d1869980d79572f2bb47a89c180a71783319956441b2fd
@@ -183,7 +183,8 @@ class StandardError
183
183
  # user friendly message, for overid
184
184
  def user_message
185
185
  return _translate if description.present? || tkey.present?
186
- "#{_translate} (#{user_digests})"
186
+ return "#{_translate} (#{user_digests})" unless defined?(@coaster)
187
+ message
187
188
  rescue => e
188
189
  "#{message} (user_message_error - #{e.class.name} #{e.message})"
189
190
  end
@@ -40,7 +40,7 @@ module Coaster
40
40
  prop_hash = {type: type, getter: getter, setter: setter, setter_callback: setter_callback, default: default}.merge(key)
41
41
  prop_hash.delete(:key)
42
42
  end
43
- serialized_property(serialize_column, key_name, prop_hash)
43
+ serialized_property(serialize_column, key_name, **prop_hash)
44
44
  end
45
45
  end
46
46
 
@@ -0,0 +1,26 @@
1
+ module Coaster
2
+ module Util
3
+ FLATTEN_HASH_DELIMITER = '.'.freeze
4
+
5
+ class << self
6
+ def flatten_hashify(object, delimiter: FLATTEN_HASH_DELIMITER, breadcrumbs: [], include_array: nil)
7
+ case object
8
+ when Hash
9
+ object.each_with_object({}) do |(key, value), memo|
10
+ memo.merge!(flatten_hashify(value, breadcrumbs: breadcrumbs + [key], include_array: include_array))
11
+ end
12
+ when Array
13
+ if include_array
14
+ object.each.with_index(1).with_object({}) do |(element, ix), memo|
15
+ memo.merge!(flatten_hashify(element, breadcrumbs: breadcrumbs + [ix], include_array: include_array))
16
+ end
17
+ else
18
+ {breadcrumbs.join(delimiter) => object}
19
+ end
20
+ else
21
+ {breadcrumbs.join(delimiter) => object}
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module Coaster
2
- VERSION = '1.3.13'
2
+ VERSION = '1.3.16'
3
3
  end
@@ -88,7 +88,7 @@ module Coaster
88
88
  assert_nil e.description
89
89
  assert_nil e.desc
90
90
  assert_equal 'Test sample error', e._translate
91
- assert_equal 'Test sample error (cbe233)', e.user_message
91
+ assert_equal 'Test sample error (Coaster::TestStandardError::SampleError)', e.user_message
92
92
  assert_equal 'Test this title', e.title
93
93
  e = SampleError.new('developer message')
94
94
  assert_equal "developer message", e.to_s
@@ -312,10 +312,11 @@ LOG
312
312
  def test_to_hash
313
313
  aa # raise NameError
314
314
  rescue => e
315
+ bt = e.digest_backtrace
315
316
  assert_equal 'NameError', e.to_hash['type']
316
317
  assert_equal 999999, e.to_hash['status']
317
318
  assert_equal 500, e.to_hash['http_status']
318
- assert_equal 'standard error translation (a962bd 3a7cb999)', e.user_message
319
+ assert_equal "standard error translation (a962bd #{bt})", e.user_message
319
320
  assert_match(/undefined local variable or method `aa'/, e.to_hash['message'])
320
321
  end
321
322
 
@@ -357,24 +358,26 @@ LOG
357
358
  begin
358
359
  raise SampleError, 'asdff'
359
360
  rescue => e
360
- assert_equal e.user_message, 'Test sample error (0dba9e f0fa4c35)'
361
+ bt = e.digest_backtrace
362
+ assert_equal "Test sample error (0dba9e #{bt})", e.user_message
361
363
  end
362
364
  begin
363
365
  raise SampleErrorSub, 'asdff'
364
366
  rescue => e
365
- assert_equal e.user_message, 'Test sample error (asdff)'
367
+ assert_equal 'Test sample error (asdff)', e.user_message
366
368
  end
367
369
  begin
368
370
  raise SampleErrorSubSub, 'asdff'
369
371
  rescue => e
370
- assert_equal e.user_message, 'Test sample error (asdff)'
372
+ assert_equal 'Test sample error (asdff)', e.user_message
371
373
  end
372
374
 
373
375
  SampleErrorSubSub.user_digests_with_default!
374
376
  begin
375
377
  raise SampleErrorSubSub, 'asdff'
376
378
  rescue => e
377
- assert_equal e.user_message, 'Test sample error (58ee3f 3d0f84b9)'
379
+ bt = e.digest_backtrace
380
+ assert_equal "Test sample error (58ee3f #{bt})", e.user_message
378
381
  end
379
382
  end
380
383
  end
data/test/test_util.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+ require 'minitest/autorun'
3
+ require 'coaster/util'
4
+
5
+ module Coaster
6
+ class TestUtil < Minitest::Test
7
+ def setup
8
+ end
9
+
10
+ def teardown
11
+ end
12
+
13
+ def test_flatten_hashify
14
+ res = Util.flatten_hashify({a: [1], b: {aa: 1, bb: [2, 1]}})
15
+ assert_equal({"a"=>[1], "b.aa"=>1, "b.bb"=>[2, 1]}, res)
16
+ res = Util.flatten_hashify({a: [1], b: {aa: 1, bb: [2, 1]}}, include_array: true)
17
+ assert_equal({"a.1"=>1, "b.aa"=>1, "b.bb.1"=>2, "b.bb.2"=>1}, res)
18
+ res = Util.flatten_hashify([{a: 1}, 22, [33, 44], {b: {c: [33, {d: 4}]}}])
19
+ assert_equal({""=>[{:a=>1}, 22, [33, 44], {:b=>{:c=>[33, {:d=>4}]}}]}, res) # no meaning result
20
+ res = Util.flatten_hashify([{a: 1}, 22, [33, 44], {b: {c: [33, {d: 4}]}}], include_array: true)
21
+ assert_equal({"1.a"=>1, "2"=>22, "3.1"=>33, "3.2"=>44, "4.b.c.1"=>33, "4.b.c.2.d"=>4}, res)
22
+ end
23
+ end
24
+ 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: 1.3.13
4
+ version: 1.3.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - buzz jung
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-08 00:00:00.000000000 Z
11
+ date: 2022-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -158,6 +158,7 @@ files:
158
158
  - lib/coaster/rails_ext.rb
159
159
  - lib/coaster/rails_ext/backtrace_cleaner.rb
160
160
  - lib/coaster/serialized_properties.rb
161
+ - lib/coaster/util.rb
161
162
  - lib/coaster/version.rb
162
163
  - test/locales/en.yml
163
164
  - test/test_backtrace.rb
@@ -165,6 +166,7 @@ files:
165
166
  - test/test_month.rb
166
167
  - test/test_object_translation.rb
167
168
  - test/test_standard_error.rb
169
+ - test/test_util.rb
168
170
  homepage: http://github.com/frograms/coaster
169
171
  licenses:
170
172
  - MIT
@@ -195,3 +197,4 @@ test_files:
195
197
  - test/test_month.rb
196
198
  - test/test_object_translation.rb
197
199
  - test/test_standard_error.rb
200
+ - test/test_util.rb