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.
98 99 100 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 98 def address @address end |
#id ⇒ Addressable::URI
Holds service identifier.
66 67 68 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 66 def id @id end |
#name ⇒ Symbol
Holds service name.
58 59 60 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 58 def name @name end |
#procs ⇒ Array
Holds procedure descriptions.
106 107 108 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 106 def procs @procs end |
#summary ⇒ String
Holds service summary.
82 83 84 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 82 def summary @summary end |
#url ⇒ Addressable::URI
Holds service help URL.
90 91 92 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 90 def url @url end |
#version ⇒ String
Holds service version.
74 75 76 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 74 def version @version end |
Class Method Details
.create(name, id, opts = { }) ⇒ V11:ServiceDescription
Creates new one.
119 120 121 122 123 124 125 126 127 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 119 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.
197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 197 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.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 133 def check! self.normalize! if not @name.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.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.array? @procs.each { |proc| proc.check! } end end end |
#output ⇒ Hash
Renders data to output hash.
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 189 190 |
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 160 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 |