File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -13,10 +13,25 @@ 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+ visibility_was = visibility
19+ self . visibility = ident . first . to_sym
20+ parse_block ( statement . parameters . first , visibility : visibility )
21+ self . visibility = visibility_was
22+ return
23+ end
24+ process_decorator do |method |
25+ method . visibility = ident . first if method . respond_to? :visibility=
26+ end
27+ when :fcall
1728 process_decorator do |method |
1829 method . visibility = ident . first if method . respond_to? :visibility=
1930 end
2031 end
2132 end
33+
34+ def is_attribute_method? ( node )
35+ node . type == :command && node . jump ( :ident ) . first . to_s =~ /^attr_(accessor|writer|reader)$/
36+ end
2237end
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