Class: RailsApiDoc::Controller::Request::Param
- Inherits:
-
Param
- Object
- Param
- RailsApiDoc::Controller::Request::Param
show all
- Defined in:
- lib/rails_api_doc/controller/request/param.rb
Constant Summary
Constants inherited
from Param
Param::COMMON_VALID_KEYS, Param::HELPER_KEYS, Param::VALID_KEYS, Param::VALID_REQUEST_KEYS, Param::VALID_RESPONSE_KEYS
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Param
#add_updated_field, #created?, define_accessors, #destroyed?, #display_type, #display_value, #updated?
Constructor Details
#initialize(name, store, is_new: false) ⇒ Param
Returns a new instance of Param.
39
40
41
42
43
44
45
|
# File 'lib/rails_api_doc/controller/request/param.rb', line 39
def initialize(name, store, is_new: false)
@name = name
@store = store
@new = []
@is_new = is_new
end
|
Class Method Details
.accepted_nested_type?(type) ⇒ Boolean
17
18
19
|
# File 'lib/rails_api_doc/controller/request/param.rb', line 17
def self.accepted_nested_type?(type)
type.in?(RailsApiDoc::NESTED_TYPES)
end
|
.valid_enum?(type, enum) ⇒ Boolean
27
28
29
30
31
|
# File 'lib/rails_api_doc/controller/request/param.rb', line 27
def self.valid_enum?(type, enum)
return false unless type == :enum
return if enum.is_a?(Array)
raise ArgumentError, 'Enum must be an array.'
end
|
.valid_nested?(type, block_given) ⇒ Boolean
33
34
35
36
37
|
# File 'lib/rails_api_doc/controller/request/param.rb', line 33
def self.valid_nested?(type, block_given)
return false unless accepted_nested_type?(type)
return true if block_given
raise ArgumentError, 'Empty object passed.'
end
|
.valid_type?(type) ⇒ Boolean
21
22
23
24
25
|
# File 'lib/rails_api_doc/controller/request/param.rb', line 21
def self.valid_type?(type)
return if type.nil? || type.in?(RailsApiDoc::ACCEPTED_TYPES)
raise ArgumentError, "Wrong type: #{type}. " \
"Correct types are: #{RailsApiDoc::ACCEPTED_TYPES}."
end
|
Instance Method Details
#display_name ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/rails_api_doc/controller/request/param.rb', line 63
def display_name
title = @name.to_s
title += '*' if required?
title
end
|
#display_special ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/rails_api_doc/controller/request/param.rb', line 51
def display_special
spec = if enum?
enum
elsif nested? || model?
model
end
spec = spec.to_s + "(#{param.special})" if param&.special
spec
end
|
#nested? ⇒ Boolean
47
48
49
|
# File 'lib/rails_api_doc/controller/request/param.rb', line 47
def nested?
self.class.accepted_nested_type?(@store[:type])
end
|