Class: Xing::Services::ErrorConverter
- Inherits:
-
Object
- Object
- Xing::Services::ErrorConverter
- Defined in:
- lib/xing/services/error_converter.rb
Instance Attribute Summary collapse
-
#am_object ⇒ Object
readonly
Returns the value of attribute am_object.
Instance Method Summary collapse
- #convert ⇒ Object
-
#initialize(am_object) ⇒ ErrorConverter
constructor
A new instance of ErrorConverter.
-
#json_errors ⇒ Object
This is a terrible hack to preserve the semantic meaning of different error types – neccesary because ActiveModel::Errors frustratingly translates semantic error messages through i18n as soon as it gets them.
- #regular_errors ⇒ Object
Constructor Details
#initialize(am_object) ⇒ ErrorConverter
Returns a new instance of ErrorConverter.
6 7 8 |
# File 'lib/xing/services/error_converter.rb', line 6 def initialize(am_object) @am_object = am_object end |
Instance Attribute Details
#am_object ⇒ Object (readonly)
Returns the value of attribute am_object.
9 10 11 |
# File 'lib/xing/services/error_converter.rb', line 9 def am_object @am_object end |
Instance Method Details
#convert ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/xing/services/error_converter.rb', line 33 def convert final_errors = {} json_errors.each_key do |key| final_errors[key] = { :type => json_errors[key][0], :message => regular_errors[key][0] } end final_errors end |
#json_errors ⇒ Object
This is a terrible hack to preserve the semantic meaning of different error types – neccesary because ActiveModel::Errors frustratingly translates semantic error messages through i18n as soon as it gets them
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/xing/services/error_converter.rb', line 15 def json_errors @json_errors ||= begin old_locale = I18n.locale I18n.locale = "json" am_object.valid? error_hash = am_object.errors.to_hash.deep_dup I18n.locale = old_locale error_hash end end |
#regular_errors ⇒ Object
26 27 28 29 30 31 |
# File 'lib/xing/services/error_converter.rb', line 26 def regular_errors @regular_errors ||= begin am_object.valid? am_object.errors.to_hash.deep_dup end end |