lsegal / yard

YARD is a Ruby Documentation tool. The Y stands for "Yay!"
http://yardoc.org
MIT License
1.94k stars 397 forks source link

Reverted referencing possible? #504

Closed 2called-chaos closed 12 years ago

2called-chaos commented 12 years ago

Can anybody tell me if this is possible in YARD and if not if it will be added or not.

I want to declare dependencies like this:

class Foo

  # doing really cool things!
  # @depends Foo#fancy_magic
  def test
    # doing something
  end

  # doing something else
  # @depends Foo#fancy_magic
  def test2
    # doing something else
  end

  # does a lot of magic
  def fancy_magic
    # doing fancy things
  end
end

Just listing the dependencies would be easily doen with a custom tag. But now I want to automatically list all methods depending on fancy_magic:

Method fancy_magic

Affects: Foo#test, Foo#test2

I hope it is clear what I mean and someone can help me ;-) Thank you in advance!

lsegal commented 12 years ago

You would write a template customization or plugin to display this. There is documentation in the yard docs on writing custom templates (see http://yardoc.org/guides). In this case you would customize the method_details template to show this information. You could just collect all methods that have the correct @depends tag. It might look something like:

Registry.all(:method).select {|o| o.has_tag?(:depends) && o.tag(:depends).text == object.path }

As a performance note, the above is a very naive implementation, and would be very slow. You could optimize it easily to map all the affected methods in one pass (O(n)), rather than looping over all methods for each method template (O(n^2))