lib/lazydoc.rb in lazydoc-0.1.0 vs lib/lazydoc.rb in lazydoc-0.2.0
- old
+ new
@@ -47,10 +47,30 @@
# Returns a comment_class instance corresponding to the line.
def register(source_file, line_number, comment_class=Comment)
Lazydoc[source_file].register(line_number, comment_class)
end
+ # Registers the method at the specified index in the call stack, to
+ # the file where the method was called. Using the default index of
+ # 1, register_caller registers the caller of the method where
+ # register_caller is called. For instance:
+ #
+ # module Sample
+ # module_function
+ # def method
+ # Lazydoc.register_caller
+ # end
+ # end
+ #
+ # # this is the line that gets registered
+ # Sample.method
+ #
+ def register_caller(comment_class=Comment, caller_index=1)
+ caller[caller_index] =~ CALLER_REGEXP
+ Lazydoc[$1].register($3.to_i - 1, comment_class)
+ end
+
# Resolves all lazydocs which include the specified code comments.
def resolve_comments(comments)
registry.each do |doc|
next if (comments & doc.comments).empty?
doc.resolve
@@ -170,9 +190,11 @@
comment.subject = value
yield(const_name, key, comment)
end
end
+ # Parses the usage for a file, ie the first comment in the file
+ # following an optional bang line.
def usage(path, cols=80)
scanner = StringScanner.new(File.read(path))
scanner.scan(/^#!.*?$/)
Comment.parse(scanner, false).wrap(cols, 2).strip
end
\ No newline at end of file