class YARD::Dry::Initializer::ParamHandler

Public Instance Methods

process() click to toggle source
# File lib/yard/dry/initializer/param_handler.rb, line 14
def process
  super

  add_constructor_param
  add_constructor_tag
end

Protected Instance Methods

add_constructor_param() click to toggle source
# File lib/yard/dry/initializer/param_handler.rb, line 23
def add_constructor_param
  existing_index = constructor.parameters.index do |name, _default|
    name == definition_name
  end
  if existing_index
    constructor.parameters[existing_index] = [definition_name, default_string]
  else
    constructor.parameters.insert(last_param_index, [definition_name, default_string])
  end
end
add_constructor_tag() click to toggle source
# File lib/yard/dry/initializer/param_handler.rb, line 39
def add_constructor_tag
  if existing_tag
    existing_tag.text = comment
    existing_tag.instance_variable_set(:@defaults, default_string && [default_string])
  else
    param = YARD::Tags::DefaultTag.new(:param, comment, nil, definition_name, [default_string])
    constructor.add_tag(param)
  end
end
existing_tag() click to toggle source
# File lib/yard/dry/initializer/param_handler.rb, line 49
def existing_tag
  @existing_tag ||=
    constructor.tags.find do |tag|
      tag.name == definition_name && tag.tag_name == 'param'
    end
end
last_param_index() click to toggle source
# File lib/yard/dry/initializer/param_handler.rb, line 34
def last_param_index
  return -1 if constructor.parameters.empty?
  constructor.parameters.last.first.start_with?('**') ? -2 : -1
end