Class: JsonRpcObjects::V11::WD::ServiceDescription

Inherits:
Generic::Object show all
Defined in:
lib/json-rpc-objects/v11/wd/service-description.rb

Overview

Service description object class.

Direct Known Subclasses

Alt::ServiceDescription

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

Attributes inherited from Generic::Object

#serializer

Class Method Summary collapse

Instance Method Summary collapse

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

#addressAddressable::URI

Holds service address.

Returns:

  • (Addressable::URI)


96
97
98
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 96

def address
  @address
end

#idAddressable::URI

Holds service identifier.

Returns:

  • (Addressable::URI)


64
65
66
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 64

def id
  @id
end

#nameSymbol

Holds service name.

Returns:

  • (Symbol)


56
57
58
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 56

def name
  @name
end

#procsArray

Holds procedure descriptions.

Returns:

  • (Array)


104
105
106
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 104

def procs
  @procs
end

#summaryString

Holds service summary.

Returns:

  • (String)


80
81
82
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 80

def summary
  @summary
end

#urlAddressable::URI

Holds service help URL.

Returns:

  • (Addressable::URI)


88
89
90
# File 'lib/json-rpc-objects/v11/wd/service-description.rb', line 88

def url
  @url
end

#versionString

Holds service version.

Returns:

  • (String)


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.

Parameters:

  • name (Symbol)

    name of the service

  • id (String)

    ID of the service (according to specification it should be valid URI)

  • opts (Hash) (defaults to: { })

    additional options

Returns:

  • (V11:ServiceDescription)

    new description object



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.

Parameters:



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

#outputHash

Renders data to output hash.

Returns:

  • (Hash)

    with data of description



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