errawr 1.1.4 → 1.1.5

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
  SHA1:
3
- metadata.gz: 445bc92a0e798063b53eca8e4b89f255e5b4bd16
4
- data.tar.gz: 50e6dfac8f166b94ed58b439c6a365c76c02be1c
3
+ metadata.gz: 9cdb0163333b17834affa6e46695e686854e55af
4
+ data.tar.gz: 03d483953b7d9475bda81f4736374ab14f7af06f
5
5
  SHA512:
6
- metadata.gz: 17af17bb709bf0596340f53344e98a16039fa4b401fd8926605d20fb969ee580b2b040693c575b43d55f4c7cdc5e8822681bf4f086da9de2568196e3b3e64047
7
- data.tar.gz: 3e4426437cfceb2c5e43a952b95337c85fb5e783f0f2c87f7c2d7c02eb30fae01c4ea5a7f020d5f09fd423e376838ff6afe076bf6c6083b8d3a6a1d0b3f8b689
6
+ metadata.gz: f7e2436befdf2d0bde0d5cbaa3ce7966e13a44e7dbd7e33472086386e4754a475728518051980d9fd53728f404ef424bb4cbc6d1d4832471a31ed082d6c6967b
7
+ data.tar.gz: e5697f37f96b376adbc6b3705cbef2e1adfa6d6e2607dd995cb585a91a3fc6140649c6a06d688245f28fa0c6c7d92cbb0e4bf64c0e694451624948cd45610517
data/lib/errawr/error.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Errawr
2
2
  class Error < StandardError
3
- attr_reader :key, :context, :metadata, :message
3
+ attr_reader :key, :context, :metadata
4
4
 
5
5
  def initialize(key = :unknown, context = {})
6
6
  @key = key
@@ -10,13 +10,18 @@ module Errawr
10
10
  process_message
11
11
  end
12
12
 
13
+ def message
14
+ @context[:message]
15
+ end
16
+
13
17
  private
14
18
  def process_context(context)
15
19
  if @i18n.kind_of?(Hash)
16
20
  @context = @i18n.merge(context)
17
21
  @context.delete(:metadata)
22
+ @message_overridden = context.include?(:message)
18
23
  else
19
- @context = {}
24
+ @context = context
20
25
  end
21
26
  end
22
27
 
@@ -29,10 +34,14 @@ module Errawr
29
34
 
30
35
  def process_message
31
36
  if @i18n.kind_of?(Hash)
32
- key = 'errawr.' + @key.to_s + '.message'
33
- @message = I18n.t(key, @context.merge({ default: I18n.t('errawr.unknown', @context) }))
37
+ if @message_overridden
38
+ @context[:message]
39
+ else
40
+ key = 'errawr.' + @key.to_s + '.message'
41
+ @context[:message] = I18n.t(key, @context.merge({ default: I18n.t('errawr.unknown', @context) }))
42
+ end
34
43
  else
35
- @message = I18n.t('errawr.' + @key.to_s, @context)
44
+ @context[:message] = I18n.t('errawr.' + @key.to_s, @context) unless @context[:message]
36
45
  end
37
46
  end
38
47
  end
@@ -1,3 +1,3 @@
1
1
  module Errawr
2
- VERSION = '1.1.4'
2
+ VERSION = '1.1.5'
3
3
  end
data/spec/errawr_spec.rb CHANGED
@@ -60,5 +60,21 @@ describe Errawr do
60
60
  e.message.should == 'Some error has occurred: interpolated message'
61
61
  end
62
62
  end
63
+
64
+ it 'should return an overridden message for a non-hashed locale' do
65
+ begin
66
+ Errawr.error!(:some_error, message: 'Overridden error message')
67
+ rescue => e
68
+ e.message.should == 'Overridden error message'
69
+ end
70
+ end
71
+
72
+ it 'should return an overridden message for a hashed locale' do
73
+ begin
74
+ Errawr.error!(:error_hash, message: 'Overridden error message')
75
+ rescue => e
76
+ e.message.should == 'Overridden error message'
77
+ end
78
+ end
63
79
  end
64
80
  end
data/spec/error_spec.rb CHANGED
@@ -20,9 +20,4 @@ describe Errawr::Error do
20
20
  error = Errawr::Error.new(:bad_error_hash)
21
21
  error.message.should == 'An unknown error has occurred'
22
22
  end
23
-
24
- it 'should insert custom values into the context if I18n value is a hash' do
25
- error = Errawr::Error.new(:error_hash)
26
- error.metadata[:name].should == 'error_name'
27
- end
28
23
  end
data/spec/mapper_spec.rb CHANGED
@@ -36,5 +36,23 @@ describe Errawr::Mapper do
36
36
  e.metadata.include?(:error).should be_false
37
37
  end
38
38
  end
39
+
40
+ it 'should return an overridden message for a non-hashed locale' do
41
+ Errawr.register!(:some_error, message: 'Overridden error message')
42
+ begin
43
+ Errawr.error!(:some_error)
44
+ rescue => e
45
+ e.message.should == 'Overridden error message'
46
+ end
47
+ end
48
+
49
+ it 'should return an overridden message for a hashed locale' do
50
+ Errawr.register!(:error_hash, message: 'Overridden error message')
51
+ begin
52
+ Errawr.error!(:error_hash)
53
+ rescue => e
54
+ e.message.should == 'Overridden error message'
55
+ end
56
+ end
39
57
  end
40
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: errawr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Smith