Class: DoctorSwagger::Parameter
- Inherits:
-
Object
- Object
- DoctorSwagger::Parameter
show all
- Defined in:
- lib/doctor_swagger/parameter.rb
Defined Under Namespace
Classes: InvalidType
Constant Summary
collapse
- ALLOWED_TYPES =
[:string, :integer, :long, :double, :boolean]
Instance Method Summary
collapse
Constructor Details
#initialize(name, &block) ⇒ Parameter
Returns a new instance of Parameter.
10
11
12
13
14
15
16
17
18
|
# File 'lib/doctor_swagger/parameter.rb', line 10
def initialize(name, &block)
@name = name
@description = ""
@required = false
@allow_multiple = false
@allowable_values = []
@data_type = :string
instance_eval(&block)
end
|
Instance Method Details
#allow_multiple! ⇒ Object
28
29
30
|
# File 'lib/doctor_swagger/parameter.rb', line 28
def allow_multiple!
@allow_multiple = true
end
|
#allowable_values(*values) ⇒ Object
32
33
34
|
# File 'lib/doctor_swagger/parameter.rb', line 32
def allowable_values(*values)
@allowable_values |= values
end
|
#allowable_values_as_json ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/doctor_swagger/parameter.rb', line 41
def allowable_values_as_json
if @allowable_values && !@allowable_values.empty?
{
'allowableValues' => {
'valueType' => 'LIST',
'values' => @allowable_values.map(&:to_s)
}
}
else
{}
end
end
|
#as_json ⇒ Object
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/doctor_swagger/parameter.rb', line 54
def as_json(*)
{
'name' => @name.to_s,
'description' => @description,
'dataType' => @data_type.to_s,
'required' => @required,
'allowMultiple' => @allow_multiple,
'paramType' => param_type
}.merge(allowable_values_as_json)
end
|
#description(description) ⇒ Object
20
21
22
|
# File 'lib/doctor_swagger/parameter.rb', line 20
def description(description)
@description = description
end
|
#required! ⇒ Object
24
25
26
|
# File 'lib/doctor_swagger/parameter.rb', line 24
def required!
@required = true
end
|
#type(type) ⇒ Object
36
37
38
39
|
# File 'lib/doctor_swagger/parameter.rb', line 36
def type(type)
raise InvalidType.new(type) unless ALLOWED_TYPES.include?(type)
@data_type = type
end
|