Exception: ZendeskAppsSupport::Validations::ValidationError
- Inherits:
-
StandardError
- Object
- StandardError
- ZendeskAppsSupport::Validations::ValidationError
- Defined in:
- lib/zendesk_apps_support/validations/validation_error.rb
Defined Under Namespace
Classes: DeserializationError
Constant Summary collapse
- KEY_PREFIX =
'txt.apps.admin.error.app_build.'
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.
47 48 49 50 |
# File 'lib/zendesk_apps_support/validations/validation_error.rb', line 47 def initialize(key, data = nil) @key = key @data = symbolize_keys(data || {}) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
45 46 47 |
# File 'lib/zendesk_apps_support/validations/validation_error.rb', line 45 def data @data end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
45 46 47 |
# File 'lib/zendesk_apps_support/validations/validation_error.rb', line 45 def key @key end |
Class Method Details
.from_hash(hash) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/zendesk_apps_support/validations/validation_error.rb', line 26 def from_hash(hash) raise DeserializationError, hash unless hash['class'] klass = constantize(hash['class']) raise DeserializationError, hash unless klass <= self klass.vivify(hash) end |
.from_json(json) ⇒ Object
Turn a JSON string into a ValidationError.
18 19 20 21 22 23 24 |
# File 'lib/zendesk_apps_support/validations/validation_error.rb', line 18 def from_json(json) hash = JSON.parse(json) raise DeserializationError, json unless hash.is_a?(Hash) from_hash(hash) rescue JSON::ParserError, NameError raise DeserializationError, json end |
.vivify(hash) ⇒ Object
Turn a Hash into a ValidationError. Used within from_json.
34 35 36 |
# File 'lib/zendesk_apps_support/validations/validation_error.rb', line 34 def vivify(hash) new(hash['key'], hash['data']) end |
Instance Method Details
#as_json ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/zendesk_apps_support/validations/validation_error.rb', line 60 def as_json(*) { 'class' => self.class.to_s, 'key' => key, 'data' => data } end |
#to_json ⇒ Object
56 57 58 |
# File 'lib/zendesk_apps_support/validations/validation_error.rb', line 56 def to_json(*) JSON.generate(as_json) end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/zendesk_apps_support/validations/validation_error.rb', line 52 def to_s ZendeskAppsSupport::I18n.t("#{KEY_PREFIX}#{key}", **data) end |