module EntityResponseConcern
Public Instance Methods
add_errors(error)
click to toggle source
# File lib/stbaldricks/entities/concerns/entity_response_concern.rb, line 7 def add_errors(error) errors.clear unless error.fields.nil? count = error.fields.length error.fields.each do |field| field = field.gsub('_id', '') # Hacky, since API returns DB field that errored instead of View Field errors.add(field, error.details) if respond_to?(field.to_sym) errors.add(:base, "#{field}: #{error.details}") unless respond_to?(field.to_sym) end end errors.instance_variable_set(:@code, error.code) errors.instance_variable_set(:@type, error.type) errors.add(:base, "#{error.type}: #{error.details}") if count&.zero? end
data()
click to toggle source
# File lib/stbaldricks/entities/concerns/entity_response_concern.rb, line 45 def data log_deprecated('data', caller) self end
error?()
click to toggle source
# File lib/stbaldricks/entities/concerns/entity_response_concern.rb, line 26 def error? !success? end
errors?()
click to toggle source
# File lib/stbaldricks/entities/concerns/entity_response_concern.rb, line 34 def errors? errors.count.positive? end
errors_http_code=(http_code)
click to toggle source
# File lib/stbaldricks/entities/concerns/entity_response_concern.rb, line 22 def errors_http_code=(http_code) errors.instance_variable_set(:@http_code, http_code) end
http_code()
click to toggle source
Deprecated Methods ############
# File lib/stbaldricks/entities/concerns/entity_response_concern.rb, line 40 def http_code log_deprecated('http_code', caller) errors.http_code end
success?()
click to toggle source
# File lib/stbaldricks/entities/concerns/entity_response_concern.rb, line 30 def success? !errors? end
Private Instance Methods
log_deprecated(method_name, method_caller = nil)
click to toggle source
# File lib/stbaldricks/entities/concerns/entity_response_concern.rb, line 57 def log_deprecated(method_name, method_caller = nil) SBF::Client::Configuration.logger.warn do caller_message = method_caller.nil? ? '' : " Called from #{method_caller.first}" "[DEPRECATION] Use of the SBF::Client::Api::Response Interface (including the `#{method_name}` method) is deprecated"\ " for #{self.class}. Please update your code to use the #{self.class} interface accordingly. #{caller_message}" end end
single_active_model_error()
click to toggle source
# File lib/stbaldricks/entities/concerns/entity_response_concern.rb, line 50 def single_active_model_error return if errors.empty? return [:base, errors[:base].first] if errors[:base].any? errors.first end