lsegal / yard

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

named scopes and define_method #431

Closed HoneyryderChuck closed 12 years ago

HoneyryderChuck commented 12 years ago

Greetings,

I've come across two situations which I don't see an immediate solution for. Consider define_method, which, in the most cases, will be document. But, if create an array of strings, iterate through them and define dynamically functions with define_method, these will not get documented. something like this:

%w(a b c).each do |x|
  # document this
  define_method(x) do
    puts x
  end
end 

Is there a way to work around this?

Another case is the named scope, for which I haven't found an handler on your code. I'd like to document my named scopes, in which case i'd like to define the parameters of it, and these should be visible in the scope's signature. Currently they're not, when I document the named scope as I document a regular function. something like this:

#documenting
# @param x_param
named_scope :find_x, lambda {|x_param| 
 # implementation...
}

so, param will be documented, but the scope's signature will only be: (Object) find_x

Worse than that, they show up in the documentation as instance methods, and not class methods. is there a way to work around such issues already?

Regards, Tiago Cardoso

lsegal commented 12 years ago

We discussed the define_method issue in #430, please see the response there. named_scope is not part of Ruby, it's a Rails thing, that's why it's not supported by default in YARD. You can use macros to document them, though:

# Documenting find_x
# @method find_x(x_param)
# @scope class
# @param x_param foo
# @return [SomeModel]
named_scope :find_x, lambda { }

The above is documented in the YARD getting started guide at http://yardoc.org/docs/yard/frames