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)


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

def address
  @address
end

#idAddressable::URI

Holds service identifier.

Returns:

  • (Addressable::URI)


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

def id
  @id
end

#nameSymbol

Holds service name.

Returns:

  • (Symbol)


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

def name
  @name
end

#procsArray

Holds procedure descriptions.

Returns:

  • (Array)


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

def procs
  @procs
end

#summaryString

Holds service summary.

Returns:

  • (String)


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

def summary
  @summary
end

#urlAddressable::URI

Holds service help URL.

Returns:

  • (Addressable::URI)


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

def url
  @url
end

#versionString

Holds service version.

Returns:

  • (String)


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.

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



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.

Parameters:



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

#outputHash

Renders data to output hash.

Returns:

  • (Hash)

    with data of description



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