coaster 0.5.8 → 1.0.1

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5bddf807a6efc4c93fd95053bfc91f1d14a43f6c3c5eecd441d4f80b5a5e9a89
4
- data.tar.gz: 4f57d7add97d24fabb8f150022603abae485441bff00c4eb3462032e5e84d3ee
3
+ metadata.gz: 7bb245ac61cf472e066e9f33934edfb00b715b07a2745ba30dcee503d973fbee
4
+ data.tar.gz: 133b5ae2c21130ff0b9ed27d03388b5f682b7ff95f31c2c455f2a36b62084cf4
5
5
  SHA512:
6
- metadata.gz: 93ba4e67c7ca68f5ef3165a30a15f8158bcf57b4ee4f809c2aacfcdbab17bc9967ddcd2657a75808d43f92f4a611a7df184b02ed1c6fcb484f497394ef15ce3a
7
- data.tar.gz: 813985347ab24389dca77903263031e08f4c349fc66b0d94bf07b683069c3390331fbf40103f185fb4a92ba78f44b1a6d46ef6f9e8903ebb42ec3022044ce140
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.dup : {}
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.dup : {}
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
- when Exception
33
- msg = message
34
- set_backtrace(message.backtrace)
35
- when StandardError
36
- @fingerprint = message.fingerprint
37
- @tags = message.tags
38
- @level = message.level
39
- @tkey = message.tkey
40
- @attributes = message.attributes
41
- msg = message
42
- set_backtrace(message.backtrace)
43
- when Hash then
44
- hash = message.with_indifferent_access rescue message
45
- msg = hash.delete(:m)
46
- msg = hash.delete(:msg) || msg
47
- msg = hash.delete(:message) || msg
48
- @fingerprint = hash.delete(:fingerprint) || hash.delete(:fingerprints)
49
- @tags = hash.delete(:tags) || hash.delete(:tag)
50
- @level = hash.delete(:level) || hash.delete(:severity) || @level
51
- @tkey = hash.delete(:tkey)
52
- msg = cause.message if msg.nil? && cause
53
- @attributes.merge!(hash)
54
- when String then
55
- msg = message
56
- when FalseClass, NilClass then
57
- msg = ''
58
- else
59
- msg = message
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.title
65
+ msg ||= self.class._translate
65
66
  super(msg)
66
67
  end
67
68
 
@@ -1,3 +1,3 @@
1
1
  module Coaster
2
- VERSION = '0.5.8'
2
+ VERSION = '1.0.1'
3
3
  end
@@ -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
@@ -39,20 +39,16 @@ module Coaster
39
39
  raise ExampleError, {wat: 'cha'}
40
40
  end
41
41
  rescue => e
42
- assert_equal({
43
- "wat"=>"cha",
44
- "type"=>"Coaster::TestStandardError::ExampleError",
45
- "status"=>20,
46
- "http_status"=>500,
47
- "message"=>"Test this title",
48
- "cause"=>{
49
- "frog"=>"rams",
50
- "type"=>"Coaster::TestStandardError::SampleError",
51
- "status"=>10,
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({frog: 'rams', wat: 'cha'}.with_indifferent_access, e.attr)
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 this title
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 this title
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
- assert_equal e.title, nil
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'), {extra: {something: 'other', the_other: 'something'}, fingerprint: [], tags: {}, level: 'error'}.with_indifferent_access
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.5.8
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: 2019-10-17 00:00:00.000000000 Z
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