Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indication to identify protected and private methods #1372

Open
noraj opened this issue Feb 24, 2021 · 6 comments
Open

Indication to identify protected and private methods #1372

noraj opened this issue Feb 24, 2021 · 6 comments

Comments

@noraj
Copy link

noraj commented Feb 24, 2021

--protected and --private of yard doc show protected and private methods on the documentation.
But once you have enabled them, you have public, protected and privates methods all mixed without a way to know which is what.
It would be nice to have a little badge next to protected and private methods to allow to identify them.

Expected result

Something like that

image

image

@lsegal
Copy link
Owner

lsegal commented Feb 24, 2021

It doesn't seem like your methods are correctly being detected as private/protected, YARD should already be showing these tags. This is the output for the following minimal repro:

class A
  protected

  def a; end
  def b; end

  private

  def c; end
  def d; end
end

image

@noraj
Copy link
Author

noraj commented Feb 25, 2021

Yes I can see the CSS public class set on each <li>. I also see that without --protected or --private my method still appears in yard.
I didn't use the following syntax:

class A
  protected

  def a; end
  def b; end

  private

  def c; end
  def d; end
end

but instead this one:

class A
  def a; end
  def b; end
  def c; end
  def d; end

  protected :a, :b
  private :c, :d
end

Which is valid ruby and totally works as expected

image

Also I don't know if it matters but I'm in class << self because class << self + private is similar to private_class_method and I saw there #1162 yard had issues with inline private_class_method but you said as a workaround that private_class_method was working with yard if used in a separate line. this may be different and #1162 is from 2018 but I mention it as it may lead somewhere.

So I have

class A

  class << self
    def a; end
    def b; end
    def c; end
    def d; end

    protected :a, :b
    private :c, :d
  end
end

@noraj
Copy link
Author

noraj commented Feb 25, 2021

I just tried

class A

  class << self
    def a; end
    def b; end

    protected

    def c; end
    def d; end
  end
end

Only a & b are show (which confirms that the alternative syntax shown earlier is not supported by yard) but even using the "classic" syntax seems to be bugged inside class methods but adding --protected never show the methods c & d.

It seems that whatever the syntax is potected_class_method or class << self + "section" protected or class << self + protected c:, d: yard has an issue with class methods that doesn't appears with instance methods.

Now if I tried to add the visibility and scope tags as a workaround, it hides the method even when --protected is provided to yard doc.

    # @!scope class
    # @!visibility protected

@noraj
Copy link
Author

noraj commented Feb 25, 2021

I'm digging some old maybe related issues #847, #760, #551 (I stopped after because it was getting too old)

@noraj
Copy link
Author

noraj commented Mar 2, 2021

I'll me my repository public soon so you can see the real code.

@noraj
Copy link
Author

noraj commented Mar 8, 2021

Source: https://github.com/sec-it/pass-station
Yard doc: https://sec-it.github.io/pass-station/yard/PassStation.html

@lsegal I can confirms that protected badge is displayed only for instance methods and not for class methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants