Class: SData::Diagnosis
- Inherits:
-
Object
- Object
- SData::Diagnosis
- Defined in:
- lib/s_data/diagnosis/diagnosis.rb,
lib/s_data/diagnosis/diagnosis_mapper.rb
Direct Known Subclasses
ApplicationDiagnosis, ApplicationNotFound, ApplicationUnavailable, BadQueryParameter, BadUrlSyntax, BadWhereSyntax, ContractNotFound, DatasetNotFound, ResourceKindNotFound
Defined Under Namespace
Classes: DiagnosisMapper
Constant Summary collapse
- @@sdata_attributes =
[:severity, :sdata_code, :application_code, :message, :stack_trace, :payload_path, :exception, :http_status_code]
Class Method Summary collapse
-
.construct_header_for(diagnosis_payloads) ⇒ Object
Can be called from outside to build a single header for multiple diagnoses, each of which has been constructed with (header=false) option.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Diagnosis
constructor
A new instance of Diagnosis.
- #to_xml(mode = :root) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Diagnosis
Returns a new instance of Diagnosis.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/s_data/diagnosis/diagnosis.rb', line 7 def initialize(params={}) raise "SData::Diagnosis is an abstract class; instantiate a subclass instead" if self.class == SData::Diagnosis params.each_pair do |key,value| if @@sdata_attributes.include?(key) self.send("#{key}=", value) end end if self.exception && !self. self. = self.exception. end self.sdata_code ||= self.class.name.demodulize self.severity ||= "error" end |
Class Method Details
.construct_header_for(diagnosis_payloads) ⇒ Object
Can be called from outside to build a single header for multiple diagnoses, each of which has been constructed with (header=false) option. Useful when generating multiple diagnoses inside a single Feed. Currently won’t work inside a signle Entry due to parsing problems in rAtom. Solving this problem is complex, so won’t try to implement unless we confirm it’s required. -Eugene
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/s_data/diagnosis/diagnosis.rb', line 36 def self.construct_header_for(diagnosis_payloads) document = XML::Document.new root_node = XML::Node.new("sdata:diagnoses") #TODO FIXME: SData spec says root node must be just 'xmlns=' and not 'xmlns:sdata', but this fails W3 #XML validation. Confirm which way is correct -- if former, change below line to root_node['xmlns']... root_node['xmlns:sdata'] = "#{SData.config[:schemas]['sdata']}" diagnosis_payloads.each do |diagnosis_payload| root_node << diagnosis_payload end document.root = root_node document end |
Instance Method Details
#to_xml(mode = :root) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/s_data/diagnosis/diagnosis.rb', line 21 def to_xml(mode=:root) case mode when :root return Diagnosis.construct_header_for(self.diagnosis_payload) when :feed return self.diagnosis_payload[0] when :entry return self.diagnosis_payload end end |