@@ -17,13 +17,15 @@ returns), and respects Ruby visibility semantics — without using YARD to parse
1717 Sorbet ` sig ` , new docs are inserted above the first ` sig ` .
1818- Heuristic type inference for params and return values, including conditional returns in rescue branches.
1919- Safe and aggressive update modes:
20- - safe mode inserts missing docs, merges existing doc-like blocks, and normalizes sortable tags
21- - aggressive mode rebuilds existing doc blocks
20+ - safe mode inserts missing docs, merges existing doc-like blocks, and normalizes sortable tags;
21+ - aggressive mode rebuilds existing doc blocks.
2222- Ruby 3.4+ syntax supported using Prism translation (see "Parser backend" below).
2323- Optional external type integrations:
24- - RBS via ` --rbs ` / ` --sig-dir `
25- - Sorbet via inline ` sig ` declarations and RBI files with ` --sorbet ` / ` --rbi-dir `
26- - Optional ` attr_reader ` /` attr_writer ` /` attr_accessor ` documentation via YARD ` @!attribute ` (see Configuration).
24+ - RBS via ` --rbs ` / ` --sig-dir ` ;
25+ - Sorbet via inline ` sig ` declarations and RBI files with ` --sorbet ` / ` --rbi-dir ` .
26+ - Optional ` @!attribute ` generation for:
27+ - ` attr_reader ` / ` attr_writer ` / ` attr_accessor ` ;
28+ - ` Struct.new ` declarations in both constant-assigned and class-based styles.
2729
2830Common workflows:
2931
@@ -69,7 +71,12 @@ Common workflows:
6971 * [ API (library) usage] ( #api-library-usage )
7072 * [ Configuration] ( #configuration )
7173 * [ Filtering] ( #filtering )
72- * [ Attribute macros (` attr_* ` )] ( #attribute-macros-attr_ )
74+ * [ ` attr_* ` example] ( #attr_-example )
75+ * [ ` Struct.new ` examples] ( #structnew-examples )
76+ * [ Constant-assigned struct] ( #constant-assigned-struct )
77+ * [ Class-based struct] ( #class-based-struct )
78+ * [ Merge behavior] ( #merge-behavior )
79+ * [ Param tag style] ( #param-tag-style )
7380 * [ Create a starter config] ( #create-a-starter-config )
7481 * [ CI integration] ( #ci-integration )
7582 * [ Comparison to YARD's parser] ( #comparison-to-yards-parser )
@@ -470,7 +477,6 @@ sorbet:
470477### Inline Sorbet example
471478
472479` ` ` ruby
473-
474480class Demo
475481 extend T::Sig
476482
484490Docscribe will use the Sorbet signature instead of the inferred body type:
485491
486492``` ruby
487-
488493class Demo
489494 extend T ::Sig
490495
@@ -749,51 +754,129 @@ docscribe --exclude-file '/^spec\//' lib
749754> ` /regex/` passed to ` --include` /`--exclude` is treated as a **method-id** pattern. Use `--include-file` /
750755` --exclude-file` for file regex filters.
751756
752- # ## Attribute macros (`attr_*`)
753-
754- Docscribe can generate YARD ` @!attribute` directives above ` attr_reader` , ` attr_writer` , and ` attr_accessor` .
755-
756- Enable it:
757+ Enable attribute- style documentation generation with:
757758
758759` ` ` yaml
759760emit:
760761 attributes: true
761762` ` `
762763
763- Example :
764+ When enabled, Docscribe can generate YARD ` @!attribute ` docs for :
764765
765- ` ` ` ruby
766- class User
767- attr_reader :name
766+ - ` attr_reader`
767+ - ` attr_writer`
768+ - ` attr_accessor`
769+ - ` Struct.new` declarations
768770
769- private
771+ # ## `attr_*` example
770772
771- attr_accessor :token
773+ > [!NOTE ]
774+ > - Attribute docs are inserted above the ` attr_*` call, not above generated methods (since they don’t exist as ` def`
775+ nodes).
776+ > - If RBS is enabled, Docscribe will try to use the RBS return type of the reader method as the attribute type.
777+
778+ ` ` ` ruby
779+ class User
780+ attr_accessor :name
772781end
773782` ` `
774783
775- Becomes :
784+ Generated docs :
776785
777786` ` ` ruby
778787class User
779- # @!attribute [r ] name
788+ # @!attribute [rw ] name
780789 # @return [Object]
781- attr_reader :name
790+ # @param [Object] value
791+ attr_accessor :name
792+ end
793+ ` ` `
782794
783- private
795+ # ## `Struct.new` examples
784796
785- # @!attribute [rw] token
786- # @private
787- # @return [Object]
788- # @param value [Object]
789- attr_accessor :token
797+ Docscribe supports both common ` Struct.new` declaration styles.
798+
799+ # ### Constant-assigned struct
800+
801+ ` ` ` ruby
802+ User = Struct.new(:name, :email, keyword_init: true)
803+ ` ` `
804+
805+ Generated docs:
806+
807+ ` ` ` ruby
808+ # @!attribute [rw] name
809+ # @return [Object]
810+ # @param [Object] value
811+ #
812+ # @!attribute [rw] email
813+ # @return [Object]
814+ # @param [Object] value
815+ User = Struct.new(:name, :email, keyword_init: true)
816+ ` ` `
817+
818+ # ### Class-based struct
819+
820+ ` ` ` ruby
821+ class User < Struct.new(:name, :email, keyword_init: true)
790822end
791823` ` `
792824
793- > [!NOTE ]
794- > - Attribute docs are inserted above the ` attr_*` call, not above generated methods (since they don’t exist as ` def`
795- nodes).
796- > - If RBS is enabled, Docscribe will try to use the RBS return type of the reader method as the attribute type.
825+ Generated docs:
826+
827+ ` ` ` ruby
828+ # @!attribute [rw] name
829+ # @return [Object]
830+ # @param [Object] value
831+ #
832+ # @!attribute [rw] email
833+ # @return [Object]
834+ # @param [Object] value
835+ class User < Struct.new(:name, :email, keyword_init: true)
836+ end
837+ ` ` `
838+
839+ Docscribe preserves the original declaration style and does not rewrite one form into the other.
840+
841+ # ## Merge behavior
842+
843+ Struct member docs use the same attribute documentation pipeline as ` attr_*` macros, which means they participate in the
844+ normal safe/ aggressive rewrite flow.
845+
846+ In safe mode, Docscribe can:
847+
848+ - insert full ` @!attribute` docs when no doc- like block exists
849+ - append missing struct member docs into an existing doc- like block
850+
851+ # ## Param tag style
852+
853+ Generated writer- style attribute docs respect ` doc.param_tag_style` .
854+
855+ For example, with:
856+
857+ ` ` ` yaml
858+ doc:
859+ param_tag_style: "type_name"
860+ ` ` `
861+
862+ writer params are emitted as:
863+
864+ ` ` ` ruby
865+ # @param [Object] value
866+ ` ` `
867+
868+ With:
869+
870+ ` ` ` yaml
871+ doc:
872+ param_tag_style: "name_first"
873+ ` ` `
874+
875+ they are emitted as:
876+
877+ ` ` ` ruby
878+ # @param value [Object]
879+ ` ` `
797880
798881# ## Create a starter config
799882
0 commit comments