Class: Betterdocs::JsonParamsRepresenterCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/betterdocs/json_params_representer_collector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJsonParamsRepresenterCollector

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

#paramsObject (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, **options, &block)
  element = build_element(representer, type, name, options, &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

#representerObject



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_sObject



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