Class: ApidocoDsl::Param
- Inherits:
-
Object
- Object
- ApidocoDsl::Param
- Includes:
- Documentable
- Defined in:
- lib/apidoco_dsl/param.rb
Constant Summary collapse
- SETTABLE =
['key', 'type', 'description', 'notes', 'validations', 'required']
Instance Attribute Summary collapse
-
#param_description ⇒ Object
Returns the value of attribute param_description.
-
#param_key ⇒ Object
Returns the value of attribute param_key.
-
#param_notes ⇒ Object
Returns the value of attribute param_notes.
-
#param_required ⇒ Object
Returns the value of attribute param_required.
-
#param_type ⇒ Object
Returns the value of attribute param_type.
-
#param_validations ⇒ Object
Returns the value of attribute param_validations.
-
#params ⇒ Object
Returns the value of attribute params.
-
#parent ⇒ Object
Returns the value of attribute parent.
Attributes included from Documentable
Instance Method Summary collapse
- #display_key ⇒ Object
- #doc_request_params ⇒ Object (also: #doc_response_params)
-
#initialize(param_key:, param_type:, param_description: nil, param_notes: nil, param_validations: nil, param_required: false, parent: nil) ⇒ Param
constructor
A new instance of Param.
- #method_missing(name, *args) ⇒ Object
- #set_attribute(name, value) ⇒ Object
- #to_h ⇒ Object
Methods included from Documentable
#param, #param_group, #property
Constructor Details
#initialize(param_key:, param_type:, param_description: nil, param_notes: nil, param_validations: nil, param_required: false, parent: nil) ⇒ Param
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/apidoco_dsl/param.rb', line 10 def initialize(param_key:, param_type:, param_description: nil, param_notes: nil, param_validations: nil, param_required: false, parent: nil) @param_key = param_key @param_type = param_type @param_description = param_description @param_notes = param_notes @param_validations = param_validations @param_required = param_required @parent = parent @params = [] @api = parent.api end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
29 30 31 32 |
# File 'lib/apidoco_dsl/param.rb', line 29 def method_missing(name, *args) return set_attribute(name, *args) if SETTABLE.include?(name.to_s) super end |
Instance Attribute Details
#param_description ⇒ Object
Returns the value of attribute param_description.
5 6 7 |
# File 'lib/apidoco_dsl/param.rb', line 5 def param_description @param_description end |
#param_key ⇒ Object
Returns the value of attribute param_key.
5 6 7 |
# File 'lib/apidoco_dsl/param.rb', line 5 def param_key @param_key end |
#param_notes ⇒ Object
Returns the value of attribute param_notes.
5 6 7 |
# File 'lib/apidoco_dsl/param.rb', line 5 def param_notes @param_notes end |
#param_required ⇒ Object
Returns the value of attribute param_required.
5 6 7 |
# File 'lib/apidoco_dsl/param.rb', line 5 def param_required @param_required end |
#param_type ⇒ Object
Returns the value of attribute param_type.
5 6 7 |
# File 'lib/apidoco_dsl/param.rb', line 5 def param_type @param_type end |
#param_validations ⇒ Object
Returns the value of attribute param_validations.
5 6 7 |
# File 'lib/apidoco_dsl/param.rb', line 5 def param_validations @param_validations end |
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/apidoco_dsl/param.rb', line 5 def params @params end |
#parent ⇒ Object
Returns the value of attribute parent.
5 6 7 |
# File 'lib/apidoco_dsl/param.rb', line 5 def parent @parent end |
Instance Method Details
#display_key ⇒ Object
55 56 57 58 |
# File 'lib/apidoco_dsl/param.rb', line 55 def display_key return param_key.to_s unless @parent && @parent.is_a?(Param) return "[#{param_key.to_s}]" end |
#doc_request_params ⇒ Object Also known as: doc_response_params
38 39 40 |
# File 'lib/apidoco_dsl/param.rb', line 38 def doc_request_params @params end |
#set_attribute(name, value) ⇒ Object
34 35 36 |
# File 'lib/apidoco_dsl/param.rb', line 34 def set_attribute(name, value) self.send(:"param_#{name}=", value) end |
#to_h ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/apidoco_dsl/param.rb', line 43 def to_h param = {} param['key'] = compound_key param['type'] = param_type unless param_type.nil? param['description'] = param_description unless param_description.nil? param['notes'] = param_notes unless param_notes.nil? param['required'] = param_required param['validations'] = param_validations unless param_validations.nil? return param end |