yard icon indicating copy to clipboard operation
yard copied to clipboard

Class attributes shown as inherited when namespace is included

Open rintaun opened this issue 6 years ago • 1 comments

When a mixin with one or more class attributes is included (not extended) elsewhere, any class attributes are shown as "extended from" in the destination when --embed-mixins is used.

(As an aside, --embed-mixins only seems to work with yard server if it is in a .yardopts file... is this intentional?)

Steps to reproduce

module TestMixin
  class << self
    attr_reader :some_attribute
  end
end

class TestClass
  include TestMixin
end

This is the minimal reproduction for the issue. I've done my best to remove all extraneous code and unique environment state on my machine before providing these steps:

  1. Run the following command: yard doc --embed-mixins
  2. Open the resulting doc/TestClass.html file

Actual Output

The class attribute from the mixin is shown in the class that included it.

class_ testclass documentation by yard 0 9 15 - google chrome 7_28_2018 9_56_50 pm

Expected Output

The attribute should not be shown in the class because it does not exist.

Environment details:

  • OS: Windows 10
  • Ruby version (ruby -v): ruby 2.4.4p296 (2018-03-28 revision 63013) [x64-mingw32]
  • YARD version (yard -v): yard 0.9.15

I have read the Contributing Guide.

rintaun avatar Jul 29 '18 02:07 rintaun

Actually, why does it ever do anything with class attributes and inheritance? Is there some scenario where class attributes / methods on a module become available to an inheriting class? Unless I'm missing something, there doesn't seem to be...

This also doesn't appear to be limited to class attributes with --embed-mixins. Given the following code, with and without --embed mixins produces varying results (neither of which are completely correct):

module TestMixin
    class << self
      attr_reader :mixin_class_attribute
        def mixin_class_method; end
    end
    attr_reader :mixin_instance_attribute
    def mixin_instance_method; end
end

class IncludeTestClass
    include TestMixin
end

class ExtendTestClass
    extend TestMixin
end

I've summarized the output in this gist: https://gist.github.com/rintaun/d2dd8703aee70737c625515b2a0c966b

rintaun avatar Jul 29 '18 14:07 rintaun