lib/lazydoc/document.rb in lazydoc-0.1.0 vs lib/lazydoc/document.rb in lazydoc-0.2.0

- old
+ new

@@ -1,6 +1,7 @@ require 'lazydoc/comment' +require 'lazydoc/method' module Lazydoc # A Document tracks constant attributes and code comments for a particular # source file. Documents may be assigned a default_const_name to be used @@ -98,15 +99,39 @@ end comment end - # Registers a regexp matching methods by the specified - # name. - def register_method(method, comment_class=Comment) - register(/^\s*def\s+#{method}(\W|$)/, comment_class) + # Registers a regexp matching the first method by the specified name. + def register_method(method_name, comment_class=Method) + register(Method.method_regexp(method_name), comment_class) end - + + # Registers the next comment. + # + # lazydoc = Document.new(__FILE__) + # + # lazydoc.register___ + # # this is the comment + # # that is registered + # def method(a,b,c) + # end + # + # lazydoc.resolve + # m = lazydoc.comments[0] + # m.subject # => "def method(a,b,c)" + # m.to_s # => "this is the comment that is registered" + # + def register___(comment_class=Comment, caller_index=0) + caller[caller_index] =~ CALLER_REGEXP + block = lambda do |lines| + n = $3.to_i + n += 1 while lines[n] =~ /^\s*(#.*)?$/ + n + end + register(block, comment_class) + end + # Scans str for constant attributes and adds them to to self. Code # comments are also resolved against str. If no str is specified, # the contents of source_file are used instead. # # Resolve does nothing if resolved == true. Returns true if str