Class: JsonRpcObjects::V11::WD::ServiceDescription
- Inherits:
-
Generic::Object
- Object
- Generic::Object
- JsonRpcObjects::V11::WD::ServiceDescription
- Defined in:
- lib/json-rpc-objects/v11/wd/service-description.rb
Overview
Service description object class.
Direct Known Subclasses
Constant Summary collapse
- VERSION =
Holds link to its version module.
JsonRpcObjects::V11::WD
- PROCEDURE_DESCRIPTION_CLASS =
Indicates the service procedure description class.
JsonRpcObjects::V11::WD::ServiceProcedureDescription
- VERSION_MATCHER =
Holds version number matcher.
/^\d+\.\d+/
Instance Attribute Summary collapse
-
#address ⇒ Addressable::URI
Holds service address.
-
#id ⇒ Addressable::URI
Holds service identifier.
-
#name ⇒ Symbol
Holds service name.
-
#procs ⇒ Array
Holds procedure descriptions.
-
#summary ⇒ String
Holds service summary.
-
#url ⇒ Addressable::URI
Holds service help URL.
-
#version ⇒ String
Holds service version.
Attributes inherited from Generic::Object
Class Method Summary collapse
-
.create(name, id, opts = { }) ⇒ V11:ServiceDescription
Creates new one.
Instance Method Summary collapse
-
#<<(value) ⇒ Object
Receives service procedure description objects.
-
#check! ⇒ Object
Checks correctness of the data.
-
#output ⇒ Hash
Renders data to output hash.
Methods inherited from Generic::Object
#initialize, parse, #serialize, #to_json, version
Constructor Details
This class inherits a constructor from JsonRpcObjects::Generic::Object
Instance Attribute Details
#address ⇒ Addressable::URI
Holds service address.
96 97 98 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 96 def address @address end |
#id ⇒ Addressable::URI
Holds service identifier.
64 65 66 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 64 def id @id end |
#name ⇒ Symbol
Holds service name.
56 57 58 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 56 def name @name end |
#procs ⇒ Array
Holds procedure descriptions.
104 105 106 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 104 def procs @procs end |
#summary ⇒ String
Holds service summary.
80 81 82 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 80 def summary @summary end |
#url ⇒ Addressable::URI
Holds service help URL.
88 89 90 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 88 def url @url end |
#version ⇒ String
Holds service version.
72 73 74 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 72 def version @version end |
Class Method Details
.create(name, id, opts = { }) ⇒ V11:ServiceDescription
Creates new one.
117 118 119 120 121 122 123 124 125 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 117 def self.create(name, id, opts = { }) data = { :name => name, :id => id } data.merge! opts return self::new(data) end |
Instance Method Details
#<<(value) ⇒ Object
Receives service procedure description objects.
195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 195 def <<(value) if not value.kind_of? self.class::PROCEDURE_DESCRIPTION_CLASS raise Exception::new(self.class::PROCEDURE_DESCRIPTION_CLASS.name.dup << " object expected.") end if @procs.nil? @procs = [ ] end @procs << value end |
#check! ⇒ Object
Checks correctness of the data.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 131 def check! self.normalize! if not @name.kind_of? Symbol raise Exception::new("Service name must be Symbol or convertable to Symbol.") end if not (@version.nil?) and not @version.match(self.class::VERSION_MATCHER) raise Exception::new("Version must be at least in <major>.<minor> format and must contain numbers only.") end if (not @procs.nil?) if (not @procs.kind_of? Array) or (not @procs.all? { |v| v.kind_of? self.class::PROCEDURE_DESCRIPTION_CLASS }) raise Exception::new("If procs is defined, must be an Array of " << self.class::PROCEDURE_DESCRIPTION_CLASS.name << " objects.") end if @procs.kind_of? Array @procs.each { |proc| proc.check! } end end end |
#output ⇒ Hash
Renders data to output hash.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 158 def output self.check! data = { "sdversion" => "1.0", "name" => @name.to_s, "id" => @id.to_s } if not @version.nil? data["version"] = @version end if not @summary.nil? data["summary"] = @summary end if not @help.nil? data["help"] = @help.to_s end if not @address.nil? data["address"] = @address.to_s end if not @procs.nil? data["procs"] = @procs.map { |i| i.output } end return data end |