@@ -15,7 +15,9 @@ class YARD::Handlers::RBS::AttributeHandler < YARD::Handlers::RBS::Base
1515 case statement . type
1616 when :attr_reader
1717 register_reader ( attr_name , yard_types , mscope )
18+ register_existing_attribute_method ( attr_name , "#{ attr_name } =" , :write , mscope )
1819 when :attr_writer
20+ register_existing_attribute_method ( attr_name , attr_name , :read , mscope )
1921 register_writer ( attr_name , yard_types , mscope )
2022 when :attr_accessor
2123 register_reader ( attr_name , yard_types , mscope )
@@ -26,18 +28,52 @@ class YARD::Handlers::RBS::AttributeHandler < YARD::Handlers::RBS::Base
2628 private
2729
2830 def register_reader ( name , types , scope )
29- obj = register MethodObject . new ( namespace , name , scope )
30- if types && !obj . has_tag? ( :return )
31- obj . add_tag YARD ::Tags ::Tag . new ( :return , '' , types )
32- end
31+ obj = MethodObject . new ( namespace , name , scope )
32+ obj . source ||= "def #{ name } \n @#{ name } \n end"
33+ obj . signature ||= "def #{ name } "
34+ obj = register ( obj )
35+ obj . docstring = "Returns the value of attribute #{ name } ." if obj . docstring . blank? ( false )
36+ apply_tag_types ( obj , :return , types )
37+ namespace . attributes [ obj . scope ] [ name ] ||= SymbolHash [ :read => nil , :write => nil ]
38+ namespace . attributes [ obj . scope ] [ name ] [ :read ] = obj
3339 obj
3440 end
3541
3642 def register_writer ( name , types , scope )
37- obj = register MethodObject . new ( namespace , "#{ name } =" , scope )
38- if types && !obj . has_tag? ( :param )
39- obj . add_tag YARD ::Tags ::Tag . new ( :param , '' , types , "value" )
40- end
43+ obj = MethodObject . new ( namespace , "#{ name } =" , scope )
44+ obj . parameters = [ [ 'value' , nil ] ]
45+ obj . source ||= "def #{ name } =(value)\n @#{ name } = value\n end"
46+ obj . signature ||= "def #{ name } =(value)"
47+ obj = register ( obj )
48+ obj . docstring = "Sets the attribute #{ name } \n @param value the value to set the attribute #{ name } to." if obj . docstring . blank? ( false )
49+ apply_tag_types ( obj , :param , types , "value" )
50+ namespace . attributes [ obj . scope ] [ name ] ||= SymbolHash [ :read => nil , :write => nil ]
51+ namespace . attributes [ obj . scope ] [ name ] [ :write ] = obj
4152 obj
4253 end
54+
55+ def register_existing_attribute_method ( attr_name , meth_name , type , scope )
56+ namespace . attributes [ scope ] [ attr_name ] ||= SymbolHash [ :read => nil , :write => nil ]
57+ return if namespace . attributes [ scope ] [ attr_name ] [ type ]
58+
59+ obj = namespace . children . find do |other |
60+ other . name == meth_name . to_sym && other . scope == scope
61+ end
62+
63+ namespace . attributes [ scope ] [ attr_name ] [ type ] = obj if obj
64+ end
65+
66+ def apply_tag_types ( obj , tag_name , types , tag_param_name = nil )
67+ return unless types
68+
69+ tag = obj . tags ( tag_name ) . find do |existing_tag |
70+ existing_tag . name == tag_param_name
71+ end
72+
73+ if tag
74+ tag . types ||= types
75+ else
76+ obj . add_tag YARD ::Tags ::Tag . new ( tag_name , '' , types , tag_param_name )
77+ end
78+ end
4379end
0 commit comments