Exception: ZendeskAppsSupport::Validations::ValidationError
- Inherits:
-
StandardError
- Object
- StandardError
- ZendeskAppsSupport::Validations::ValidationError
- Defined in:
- lib/zendesk_apps_support/validations/validation_error.rb
Direct Known Subclasses
Defined Under Namespace
Classes: DeserializationError
Constant Summary collapse
- KEY_PREFIX =
'txt.apps.admin.error.app_build.'.freeze
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
- .from_hash(hash) ⇒ Object
-
.from_json(json) ⇒ Object
Turn a JSON string into a ValidationError.
-
.vivify(hash) ⇒ Object
Turn a Hash into a ValidationError.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(key, data = nil) ⇒ ValidationError
constructor
A new instance of ValidationError.
- #to_json ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(key, data = nil) ⇒ ValidationError
Returns a new instance of ValidationError.
45 46 47 |
# File 'lib/zendesk_apps_support/validations/validation_error.rb', line 45 def initialize(key, data = nil) @key, @data = key, symbolize_keys(data || {}) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
43 44 45 |
# File 'lib/zendesk_apps_support/validations/validation_error.rb', line 43 def data @data end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
43 44 45 |
# File 'lib/zendesk_apps_support/validations/validation_error.rb', line 43 def key @key end |
Class Method Details
.from_hash(hash) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/zendesk_apps_support/validations/validation_error.rb', line 24 def from_hash(hash) fail DeserializationError.new(hash) unless hash['class'] klass = constantize(hash['class']) fail DeserializationError.new(hash) unless klass <= self klass.vivify(hash) end |
.from_json(json) ⇒ Object
Turn a JSON string into a ValidationError.
16 17 18 19 20 21 22 |
# File 'lib/zendesk_apps_support/validations/validation_error.rb', line 16 def from_json(json) hash = JSON.load(json) fail DeserializationError.new(json) unless hash.is_a?(Hash) from_hash(hash) rescue JSON::ParserError, NameError raise DeserializationError.new(json) end |
.vivify(hash) ⇒ Object
Turn a Hash into a ValidationError. Used within from_json.
32 33 34 |
# File 'lib/zendesk_apps_support/validations/validation_error.rb', line 32 def vivify(hash) new(hash['key'], hash['data']) end |
Instance Method Details
#as_json ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/zendesk_apps_support/validations/validation_error.rb', line 57 def as_json(*) { 'class' => self.class.to_s, 'key' => key, 'data' => data } end |
#to_json ⇒ Object
53 54 55 |
# File 'lib/zendesk_apps_support/validations/validation_error.rb', line 53 def to_json(*) JSON.generate(as_json) end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/zendesk_apps_support/validations/validation_error.rb', line 49 def to_s ZendeskAppsSupport::I18n.t("#{KEY_PREFIX}#{key}", data) end |