File tree 3 files changed +31
-1
lines changed
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
13
13
case statement . type
14
14
when :var_ref , :vcall
15
15
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
17
25
process_decorator do |method |
18
26
method . visibility = ident . first if method . respond_to? :visibility=
19
27
end
20
28
end
21
29
end
30
+
31
+ def is_attribute_method? ( node )
32
+ node . type == :command && node . jump ( :ident ) . first . to_s =~ /^attr_(accessor|writer|reader)$/
33
+ end
22
34
end
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 41
41
it "can decorate a method definition" do
42
42
expect ( Registry . at ( 'Testing#decpriv' ) . visibility ) . to eq :private
43
43
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."
44
55
end
You can’t perform that action at this time.
0 commit comments