Class: JsonRpcObjects::V11::WD::ServiceProcedureDescription

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

Overview

Description of one procedure of the service.

Direct Known Subclasses

Alt::ServiceProcedureDescription

Constant Summary collapse

VERSION =

Holds link to its version module.

JsonRpcObjects::V11::WD
PARAMETER_DESCRIPTION_CLASS =

Indicates the procedure parameter description class.

JsonRpcObjects::V11::WD::ProcedureParameterDescription

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

#idempotentBoolean

Indicates procedure idempotency.

Returns:

  • (Boolean)


74
75
76
# File 'lib/json-rpc-objects/v11/wd/service-procedure-description.rb', line 74

def idempotent
  @idempotent
end

#nameSymbol

Holds procedure name.

Returns:

  • (Symbol)


50
51
52
# File 'lib/json-rpc-objects/v11/wd/service-procedure-description.rb', line 50

def name
  @name
end

#paramsArray

Holds procedure params specification.

Returns:

  • (Array)


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

def params
  @params
end

#returnClass

Holds procedure return value specification.

Returns:

  • (Class)


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

def return
  @return
end

#summaryString

Holds procedure summary.

Returns:

  • (String)


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

def summary
  @summary
end

#urlAddressable::URI

Holds procedure help URL.

Returns:

  • (Addressable::URI)


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

def url
  @url
end

Class Method Details

.create(name, opts = { }) ⇒ V11:ServiceProcedureDescription

Creates new one.

Parameters:

  • name (Symbol)

    name of the procedure

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

    additional options

Returns:

  • (V11:ServiceProcedureDescription)

    new description object



101
102
103
104
105
# File 'lib/json-rpc-objects/v11/wd/service-procedure-description.rb', line 101

def self.create(name, opts = { })
    data = { :name => name }
    data.merge! opts
    return self::new(data)
end

Instance Method Details

#<<(value) ⇒ Object

Receives service procedure description objects.

Parameters:



180
181
182
183
184
185
186
187
188
189
190
# File 'lib/json-rpc-objects/v11/wd/service-procedure-description.rb', line 180

def <<(value)
    if not value.kind_of? self.class::PARAMETER_DESCRIPTION_CLASS
        raise Exception::new(self.class::PARAMETER_DESCRIPTION_CLASS.name.dup << " object expected.")
    end
    
    if @params.nil?
        @params = [ ]
    end
    
    @params << value
end

#check!Object

Checks correctness of the data.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/json-rpc-objects/v11/wd/service-procedure-description.rb', line 111

def check!
    self.normalize!
    
    if not @name.kind_of? Symbol
        raise Exception::new("Procedure name must be Symbol or convertable to Symbol.")
    end

    if not @params.nil? 
        if (not @params.kind_of? Array) or (not @params.all? { |v| v.kind_of? self.class::PARAMETER_DESCRIPTION_CLASS })
            raise Exception::new("If params is defined, must be an Array of " << self.class::PARAMETER_DESCRIPTION_CLASS.name << " objects.")
        end
        
        if @params.kind_of? Array
            @params.each { |param| param.check! }
        end
    end
    
    if not @return.nil?
        if not @return.kind_of? self.class::PARAMETER_DESCRIPTION_CLASS
            raise Exception::new("If return is defined, must be set to " << self.class::PARAMETER_DESCRIPTION_CLASS.name << " object.")
        end
        
        @return.check!
    end

    if (not @idempotent.nil?) and (not Utils::Object.boolean? @idempotent)
        raise Exception::new("If idempotent is defined, must be boolean.")
    end
end

#outputHash

Renders data to output hash.

Returns:

  • (Hash)

    with data of description



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/json-rpc-objects/v11/wd/service-procedure-description.rb', line 146

def output
    self.check!
    data = { "name" => @name.to_s }
    
    if not @summary.nil?
        data["summary"] = @summary
    end
    
    if not @help.nil?
        data["help"] = @help.to_s
    end
    
    if not @idempotent.nil?
        data["idempotent"] = @idempotent
    end
    
    if not @params.nil?
        data["params"] = @params.map { |i| i.output }
    end

    if not @return.nil?
        data["return"] = @return.output
    end
    
    return data
end