annotaterb icon indicating copy to clipboard operation
annotaterb copied to clipboard

Feature Request: Add Option to Place Annotations Above Nested Classes or Modules.

Open yamat47 opened this issue 11 months ago • 1 comments

Summary

Currently, annotaterb places annotations at the top of the file or above the module definition.

However, there is no option to place annotations directly above nested class or module definitions. This feature request proposes adding a new option to support this functionality.

Proposed Solution

Introduce a new option --nested-position that allows users to place annotations directly above nested classes or modules.

This will ensure that annotations are correctly positioned in the context of nested definitions.

Example

Given the following file structure (based on the current test case in collapsed_test_model.rb):

module Collapsed
  class TestModel < ApplicationRecord
    def self.table_name_prefix
      "collapsed_"
    end
  end
end

Without --nested-position Option

The annotation is placed at the top of the file:

# == Schema Information
#
# Table name: collapsed_test_models
#
#  id         :integer          not null, primary key
#  collapsed  :boolean
#  name       :string
#  created_at :datetime         not null
#  updated_at :datetime         not null
#
module Collapsed
  class TestModel < ApplicationRecord
    def self.table_name_prefix
      "collapsed_"
    end
  end
end

With --nested-position Option

The annotation is placed directly above the TestModel class:

module Collapsed
  # == Schema Information
  #
  # Table name: collapsed_test_models
  #
  #  id         :integer          not null, primary key
  #  collapsed  :boolean
  #  name       :string
  #  created_at :datetime         not null
  #  updated_at :datetime         not null
  #
  class TestModel < ApplicationRecord
    def self.table_name_prefix
      "collapsed_"
    end
  end
end

Benefits

  • Improves readability by placing annotations closer to the relevant class or module.
  • Provides more flexibility in how annotations are positioned within files.

Thank you for considering this feature request!

yamat47 avatar Feb 04 '25 12:02 yamat47

@yamat47 thank you for submitting a detailed feature request. I think it makes sense. Right now I do not have the time to add it, so I'll be adding enhancement label to this issue. Also, if you want to try implementing this I can definitely help with support and reviews.

drwl avatar Feb 17 '25 03:02 drwl

This was the thing that stopped me from using the original gem eventually. The default behavior causes the annotation to be part of the module's rdoc, not the model's rdoc.

wmakley avatar May 27 '25 15:05 wmakley

Hi @drwl!

I've created a PR for the --nested-position feature. Could you please review it when you have a chance?

Here: https://github.com/drwl/annotaterb/pull/223

Thanks!

yamat47 avatar Jun 01 '25 12:06 yamat47