errawr 1.1.5 → 1.1.6

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: 9cdb0163333b17834affa6e46695e686854e55af
4
- data.tar.gz: 03d483953b7d9475bda81f4736374ab14f7af06f
3
+ metadata.gz: be2440444126c0bf8520e79f82f1390e69840420
4
+ data.tar.gz: 54c653df41721042a39e81858e3f2fc9d5bc164b
5
5
  SHA512:
6
- metadata.gz: f7e2436befdf2d0bde0d5cbaa3ce7966e13a44e7dbd7e33472086386e4754a475728518051980d9fd53728f404ef424bb4cbc6d1d4832471a31ed082d6c6967b
7
- data.tar.gz: e5697f37f96b376adbc6b3705cbef2e1adfa6d6e2607dd995cb585a91a3fc6140649c6a06d688245f28fa0c6c7d92cbb0e4bf64c0e694451624948cd45610517
6
+ metadata.gz: eebb52e2d62840f94662258155c5d65b3b1d247b7d35ff89a6c0e8f1f6feb59332f7b1d55d7f797b4a23668c1009c000b9be67c9cf9669168b78795ff197b3ee
7
+ data.tar.gz: 789f8f217c980bd913d90bb0825631e8e79dba6c4f195a94b0acb7aea0bfd38f18f27a6d3dc767199d800ef3a037af1a240aac3e3253b69ac9ec85f64e2d12c7
data/.travis.yml CHANGED
@@ -5,4 +5,4 @@ rvm:
5
5
  - ruby-head
6
6
  - jruby-19mode
7
7
  - jruby-head
8
- - rbx-19mode
8
+ - rbx
data/Gemfile CHANGED
@@ -12,4 +12,11 @@ end
12
12
  group :test do
13
13
  gem 'rspec'
14
14
  gem 'simplecov'
15
+ end
16
+
17
+ platforms :rbx do
18
+ gem 'racc'
19
+ gem 'rubinius-coverage', github: 'rubinius/rubinius-coverage'
20
+ gem 'rubysl'
21
+ gem 'rubysl-json'
15
22
  end
data/lib/errawr/error.rb CHANGED
@@ -4,45 +4,40 @@ module Errawr
4
4
 
5
5
  def initialize(key = :unknown, context = {})
6
6
  @key = key
7
+ @context = context
8
+ @metadata = {}
7
9
  @i18n = I18n.t('errawr.' + @key.to_s)
8
- process_context(context)
9
- process_metadata(context)
10
- process_message
10
+ update_context(@context)
11
11
  end
12
12
 
13
13
  def message
14
- @context[:message]
14
+ process_message
15
+ end
16
+
17
+ def update_context(context)
18
+ process_context(context)
15
19
  end
16
20
 
17
21
  private
18
22
  def process_context(context)
23
+ @message_overridden = context.include?(:message)
19
24
  if @i18n.kind_of?(Hash)
20
- @context = @i18n.merge(context)
21
- @context.delete(:metadata)
22
- @message_overridden = context.include?(:message)
25
+ @context.merge!(@i18n.merge(context))
23
26
  else
24
- @context = context
25
- end
26
- end
27
-
28
- def process_metadata(context)
29
- if @i18n.kind_of?(Hash)
30
- context = @i18n.merge(context)
27
+ @context.merge!(context)
31
28
  end
32
- @metadata = context.fetch(:metadata, {})
29
+ @metadata.merge!(@context.delete(:metadata)) if @context.has_key?(:metadata)
33
30
  end
34
31
 
35
32
  def process_message
33
+ return @context[:message] if @message_overridden
36
34
  if @i18n.kind_of?(Hash)
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
35
+ key = 'errawr.' + @key.to_s + '.message'
36
+ @context[:message] = I18n.t(key, @context.merge({ default: I18n.t('errawr.unknown', @context) }))
43
37
  else
44
38
  @context[:message] = I18n.t('errawr.' + @key.to_s, @context) unless @context[:message]
45
39
  end
40
+ @context[:message]
46
41
  end
47
42
  end
48
43
  end
@@ -1,3 +1,3 @@
1
1
  module Errawr
2
- VERSION = '1.1.5'
2
+ VERSION = '1.1.6'
3
3
  end
data/lib/errawr.rb CHANGED
@@ -15,8 +15,7 @@ module Errawr
15
15
  module ClassMethods
16
16
  def error!(name, context = {})
17
17
  klass = Mapper[name] || Mapper[:unknown]
18
- klass.metadata.merge!(context.delete(:metadata) || {})
19
- klass.context.merge!(context)
18
+ klass.update_context(context) unless context.empty?
20
19
  raise klass
21
20
  end
22
21
 
data/spec/errawr_spec.rb CHANGED
@@ -34,15 +34,6 @@ describe Errawr do
34
34
  end
35
35
  end
36
36
 
37
- it '#register! should override custom metadata values from locale file' do
38
- Errawr.register!(:error_hash, metadata: { name: 'register!_name' })
39
- begin
40
- Errawr.error!(:error_hash)
41
- rescue => e
42
- e.metadata[:name].should == 'register!_name'
43
- end
44
- end
45
-
46
37
  it 'should override custom metadata values from #register! and locale file' do
47
38
  Errawr.register!(:error_hash, metadata: { name: 'register!_name' })
48
39
  begin
@@ -52,15 +43,6 @@ describe Errawr do
52
43
  end
53
44
  end
54
45
 
55
- it 'should interpolate locales' do
56
- Errawr.register!(:interpolated_error, error_message: 'interpolated message')
57
- begin
58
- Errawr.error!(:interpolated_error)
59
- rescue => e
60
- e.message.should == 'Some error has occurred: interpolated message'
61
- end
62
- end
63
-
64
46
  it 'should return an overridden message for a non-hashed locale' do
65
47
  begin
66
48
  Errawr.error!(:some_error, message: 'Overridden error message')
@@ -76,5 +58,14 @@ describe Errawr do
76
58
  e.message.should == 'Overridden error message'
77
59
  end
78
60
  end
61
+
62
+ it 'should pass in interpolated params' do
63
+ Errawr.register!(:interpolated_error)
64
+ begin
65
+ Errawr.error!(:interpolated_error, error_message: 'interpolated message')
66
+ rescue => e
67
+ e.message.should == 'Some error has occurred: interpolated message'
68
+ end
69
+ end
79
70
  end
80
71
  end
data/spec/mapper_spec.rb CHANGED
@@ -54,5 +54,23 @@ describe Errawr::Mapper do
54
54
  e.message.should == 'Overridden error message'
55
55
  end
56
56
  end
57
+
58
+ it 'should override custom metadata values from locale file' do
59
+ Errawr.register!(:error_hash, metadata: { name: 'register!_name' })
60
+ begin
61
+ Errawr.error!(:error_hash)
62
+ rescue => e
63
+ e.metadata[:name].should == 'register!_name'
64
+ end
65
+ end
66
+
67
+ it 'should interpolate locales' do
68
+ Errawr.register!(:interpolated_error, error_message: 'interpolated message')
69
+ begin
70
+ Errawr.error!(:interpolated_error)
71
+ rescue => e
72
+ e.message.should == 'Some error has occurred: interpolated message'
73
+ end
74
+ end
57
75
  end
58
76
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: errawr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-20 00:00:00.000000000 Z
11
+ date: 2013-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n