Class: Grape::Validations::ParamsScope::AttributesDoc
- Inherits:
-
Object
- Object
- Grape::Validations::ParamsScope::AttributesDoc
- Defined in:
- lib/grape/validations/attributes_doc.rb
Overview
Documents parameters of an endpoint. If documentation isn't needed (for instance, it is an internal API), the class only cleans up attributes to avoid junk in RAM.
Instance Attribute Summary collapse
-
#type ⇒ Object
Returns the value of attribute type.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
- #document(attrs) ⇒ Object
- #extract_details(validations) ⇒ Object
-
#initialize(api, scope) ⇒ AttributesDoc
constructor
A new instance of AttributesDoc.
- #required ⇒ Object
Constructor Details
#initialize(api, scope) ⇒ AttributesDoc
Returns a new instance of AttributesDoc.
13 14 15 16 17 |
# File 'lib/grape/validations/attributes_doc.rb', line 13 def initialize(api, scope) @api = api @scope = scope @type = type end |
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
9 10 11 |
# File 'lib/grape/validations/attributes_doc.rb', line 9 def type @type end |
#values ⇒ Object
Returns the value of attribute values.
9 10 11 |
# File 'lib/grape/validations/attributes_doc.rb', line 9 def values @values end |
Instance Method Details
#document(attrs) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/grape/validations/attributes_doc.rb', line 33 def document(attrs) return if @api.namespace_inheritable(:do_not_document) details[:type] = type.to_s if type details[:values] = values if values documented_attrs = attrs.each_with_object({}) do |name, memo| memo[@scope.full_name(name)] = details end @api.namespace_stackable(:params, documented_attrs) end |
#extract_details(validations) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/grape/validations/attributes_doc.rb', line 19 def extract_details(validations) details[:required] = validations.key?(:presence) desc = validations.delete(:desc) || validations.delete(:description) details[:desc] = desc if desc documentation = validations.delete(:documentation) details[:documentation] = documentation if documentation details[:default] = validations[:default] if validations.key?(:default) end |
#required ⇒ Object
46 47 48 |
# File 'lib/grape/validations/attributes_doc.rb', line 46 def required details[:required] end |