openstax_rescue_from 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NmZjZTU4YTYyNGM5MDQyYmQwYTJiMzIxZGM3MDRkNmM1M2RjZmM4ZQ==
4
+ MGVlN2JjZTk3NGUxZDVmOTQwMDRiMDY3Y2IyMzhlZGRlYWVhYTE1OQ==
5
5
  data.tar.gz: !binary |-
6
- ZTdjZDk5YTAwMWY5YzU2NThjNjBiOWQ1YmM1ZWUwZDdjNzIxYjJkOQ==
6
+ NTc5MDA1MWMyMGJlYzdlMzliODczMzNjYjUyNzg2ZmFmZjc4MjhkYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Y2RmMGEwOWJkMjkyZjk4OGFmOGYxMGUyNDM5MjcwMDYwMWMyNTQyMzBkYWU2
10
- YzcyZDRlYzJkNTNjNmI2ODFhZDRhOTQ1NjQ0N2MyZmJiOGM3ZWEzNTI0N2U2
11
- MzIxMDNmMjczNjkxY2RkODY5YWI2ZTg5ZjZiNDQ0ODYzMTZkMGE=
9
+ ZTc1M2UxMzQxMDAxNTc3YmMyZTU2MzY5Yzg0YTU3NTAwZWFmYWQxMTcwMTA0
10
+ YWQ3NTVjZDVjMjE0Y2Q5YTM5MTEyMmM2ZjlmOTI0YzM3ODg4ZDAxYTA4MmY2
11
+ ZTcxZWIzNjUxZGQ0YzI3YjVhZDQyZDE4OWFkNjBlMzI4ZjE0Yzg=
12
12
  data.tar.gz: !binary |-
13
- ZDUyNGM4ZTZkMGZjYjFkNGM4NDNmNGVhMWZmYmVhMWExZjc3NmJlNjhlY2Q5
14
- OWNjOTBiZjUwZmE4YTY5MDQ4NjdmNjgzNDVhNTBhNzEzOGRmMmQ4NmMzZjYx
15
- NmJjMzBjZDhkOWRiY2E5YzEyMTlmMjMwZmRlZWM5MDdlYjhkYTI=
13
+ NDY0MDFlMTBhYmYyN2NjNGM2ZWRmMTU2YTM0MDU3YTJjYWI2OGRmYzE4N2U3
14
+ OGIwNjU2MzMwZDA0NDUwZmEyMTA3OWM3Mjg3YmJlZDVhY2JhYWY3N2JhMTA4
15
+ ZGQ2ODU4NWMyODNkMDkxYTFiM2IwYmViZWI4Mjc5ZDE4MDRlMTE=
@@ -1,16 +1,18 @@
1
1
  module OpenStax
2
2
  module RescueFrom
3
3
  class ExceptionOptions
4
- attr_accessor :notify, :status_code, :extras
4
+ attr_accessor :notify, :status_code, :message, :extras
5
5
 
6
6
  def initialize(options = {})
7
7
  options.stringify_keys!
8
8
  options = { 'notify' => true,
9
9
  'status' => :internal_server_error,
10
+ 'message' => nil,
10
11
  'extras' => ->(exception) { {} } }.merge(options)
11
12
 
12
13
  @notify = options['notify']
13
14
  @status_code = options['status']
15
+ @message = options['message']
14
16
  @extras = options['extras']
15
17
  end
16
18
 
@@ -20,7 +20,7 @@ module OpenStax
20
20
  end
21
21
 
22
22
  def friendly_message
23
- RescueFrom.friendly_message(status)
23
+ RescueFrom.friendly_message(self)
24
24
  end
25
25
 
26
26
  def extras
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module RescueFrom
3
- VERSION = "1.5.0"
3
+ VERSION = "1.6.0"
4
4
  end
5
5
  end
@@ -16,8 +16,9 @@ module OpenStax
16
16
 
17
17
  def register_exception(exception, options = {})
18
18
  name = exception.is_a?(String) ? exception : exception.name
19
+ options = ExceptionOptions.new(options)
19
20
  @@registered_exceptions ||= {}
20
- @@registered_exceptions[name] = ExceptionOptions.new(options)
21
+ @@registered_exceptions[name] = options
21
22
  end
22
23
 
23
24
  def register_unrecognized_exception(exception_class, options = {})
@@ -44,8 +45,10 @@ module OpenStax
44
45
  @@registered_exceptions.select { |_, v| v.notify? }.keys
45
46
  end
46
47
 
47
- def friendly_message(status)
48
- friendly_status_messages[status] || default_friendly_message
48
+ def friendly_message(proxy)
49
+ options_for(proxy.name).message ||
50
+ friendly_status_messages[proxy.status] ||
51
+ default_friendly_message
49
52
  end
50
53
 
51
54
  def notifies_for?(exception_name)
@@ -77,6 +80,10 @@ module OpenStax
77
80
  end
78
81
 
79
82
  private
83
+ def options_for(name)
84
+ @@registered_exceptions[name]
85
+ end
86
+
80
87
  def friendly_status_messages
81
88
  @@friendly_status_messages ||= {
82
89
  internal_server_error: default_friendly_message,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_rescue_from
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Slavinsky
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2015-10-13 00:00:00.000000000 Z
12
+ date: 2015-11-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails