Class: RailsApiDoc::Model::AttributeMerger

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_api_doc/model/attribute_merger.rb

Overview

author: Vadim Shaveiko <@vshaveyko> :nodoc:

Constant Summary collapse

MODEL =
RailsApiDoc::ApiDatum
MERGABLE_FIELDS =
[:type, :desc, :action_type].freeze
@@data =
MODEL.all

Instance Method Summary collapse

Constructor Details

#initialize(attributes, api_type) ⇒ AttributeMerger

do not mutate attributes

please - impossible



16
17
18
19
# File 'lib/rails_api_doc/model/attribute_merger.rb', line 16

def initialize(attributes, api_type)
  @attrs = attributes.stringify_keys
  @api_type = api_type
end

Instance Method Details

#callObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rails_api_doc/model/attribute_merger.rb', line 31

def call
  api_params = @@data.select { |d| d.api_type == @api_type }.each do |param|
    #
    # nesting should be present for parameter to appear
    #
    next unless param.name && param.nesting.present?

    attrs, nesting, name = _parse_settings(param)

    _add_nested_param(param, nesting, attrs)
  end

  @attrs
end

#merge_action(action:, ctrl:) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/rails_api_doc/model/attribute_merger.rb', line 21

def merge_action(action:, ctrl:)
  merge_data = @@data.select { |d| d.api_type == @api_type && d.api_action == action.to_s && d.nesting.first == ctrl.name }

  merge_data.each do |param|
    _add_nested_param(param, param.nesting[1..-1], @attrs)
  end

  @attrs
end