File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -13,10 +13,22 @@ class YARD::Handlers::Ruby::VisibilityHandler < YARD::Handlers::Ruby::Base
1313 case statement . type
1414 when :var_ref , :vcall
1515 self . visibility = ident . first . to_sym
16- when :fcall , :command
16+ when :command
17+ if RUBY_VERSION >= '3.' && is_attribute_method? ( statement . parameters . first )
18+ parse_block ( statement . parameters . first , visibility : ident . first . to_sym )
19+ return
20+ end
21+ process_decorator do |method |
22+ method . visibility = ident . first if method . respond_to? :visibility=
23+ end
24+ when :fcall
1725 process_decorator do |method |
1826 method . visibility = ident . first if method . respond_to? :visibility=
1927 end
2028 end
2129 end
30+
31+ def is_attribute_method? ( node )
32+ node . type == :command && node . jump ( :ident ) . first . to_s =~ /^attr_(accessor|writer|reader)$/
33+ end
2234end
Original file line number Diff line number Diff line change 1+ class Testing
2+ private attr_accessor :inline_private_attr
3+ protected attr_writer :inline_protected_writer
4+
5+ # This one should be public
6+ attr_reader :inline_public_reader
7+ end
Original file line number Diff line number Diff line change 4141 it "can decorate a method definition" do
4242 expect ( Registry . at ( 'Testing#decpriv' ) . visibility ) . to eq :private
4343 end unless LEGACY_PARSER
44+
45+ describe 'ruby 3 specific features' do
46+ before ( :all ) { parse_file :visibility_handler_002 , __FILE__ }
47+
48+ it "handles attr_accessor when inlined" do
49+ expect ( Registry . at ( 'Testing#inline_private_attr' ) . visibility ) . to eq :private
50+ expect ( Registry . at ( 'Testing#inline_private_attr=' ) . visibility ) . to eq :private
51+ expect ( Registry . at ( 'Testing#inline_protected_writer=' ) . visibility ) . to eq :protected
52+ expect ( Registry . at ( 'Testing#inline_public_reader' ) . visibility ) . to eq :public
53+ end
54+ end if RUBY_VERSION >= "3."
4455end
You can’t perform that action at this time.
0 commit comments