Class: Betterdocs::JsonParamsRepresenterCollector
- Inherits:
-
Object
- Object
- Betterdocs::JsonParamsRepresenterCollector
- Defined in:
- lib/betterdocs/json_params_representer_collector.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #add_element(representer, type, name, **options, &block) ⇒ Object
-
#initialize ⇒ JsonParamsRepresenterCollector
constructor
A new instance of JsonParamsRepresenterCollector.
- #param(param_name) ⇒ Object
- #representer ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ JsonParamsRepresenterCollector
Returns a new instance of JsonParamsRepresenterCollector.
3 4 5 |
# File 'lib/betterdocs/json_params_representer_collector.rb', line 3 def initialize @params = {} end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
7 8 9 |
# File 'lib/betterdocs/json_params_representer_collector.rb', line 7 def params @params end |
Instance Method Details
#add_element(representer, type, name, **options, &block) ⇒ Object
14 15 16 17 |
# File 'lib/betterdocs/json_params_representer_collector.rb', line 14 def add_element(representer, type, name, **, &block) element = build_element(representer, type, name, , &block) element.add_to_collector(self) end |
#param(param_name) ⇒ Object
9 10 11 12 |
# File 'lib/betterdocs/json_params_representer_collector.rb', line 9 def param(param_name) param_name = param_name.to_sym @params[param_name] end |
#representer ⇒ Object
19 20 21 22 23 |
# File 'lib/betterdocs/json_params_representer_collector.rb', line 19 def representer @params.values.find { |v| v.representer and break v.representer } end |
#to_s ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/betterdocs/json_params_representer_collector.rb', line 25 def to_s result = "*** #{representer} ***\n" if params = @params.values.full? result << "\nProperties:" params.each_with_object(result) do |param, r| r << "\n#{param.full_name}: (#{param.types * '|'}): #{param.description}\n" end end result end |