lib/lazydoc/document.rb in lazydoc-0.9.0 vs lib/lazydoc/document.rb in lazydoc-1.0
- old
+ new
@@ -8,26 +8,26 @@
autoload(:Trailer, 'lazydoc/trailer')
# A regexp matching an attribute start or end. After a match:
#
# $1:: const_name
- # $3:: key
- # $4:: end flag
+ # $2:: key
+ # $3:: end flag
#
- ATTRIBUTE_REGEXP = /([A-Z][A-z]*(::[A-Z][A-z]*)*)?::([a-z_]+)(-?)/
+ ATTRIBUTE_REGEXP = /([A-Z][A-z]*(?:::[A-Z][A-z]*)*)?::([a-z_]+)(-?)/
# A regexp matching constants from the ATTRIBUTE_REGEXP leader
- CONSTANT_REGEXP = /#.*?([A-Z][A-z]*(::[A-Z][A-z]*)*)?$/
+ CONSTANT_REGEXP = /#.*?([A-Z][A-z]*(?:::[A-Z][A-z]*)*)?$/
# A regexp matching a caller line, to extract the calling file
# and line number. After a match:
#
# $1:: file
- # $3:: line number (as a string, obviously)
+ # $2:: line number (as a string, obviously)
#
# Note that line numbers in caller start at 1, not 0.
- CALLER_REGEXP = /^(([A-z]:)?[^:]+):(\d+)/
+ CALLER_REGEXP = /^((?:[A-z]:)?[^:]+):(\d+)/
# A Document resolves constant attributes and code comments for a particular
# source file. Documents may be assigned a default_const_name to be used
# when a constant attribute does not specify a constant.
#
@@ -38,13 +38,12 @@
# doc.resolve
#
# Document['Const::Name']['key'].value # => 'value a'
# Document['Default']['key'].value # => 'value b'
#
- # As shown in the example, constant attibutes for all documents are cached in
- # the class-level const_attrs hash and are normally consumed through Document
- # itself.
+ # As in the example, constant attibutes for all documents may be accessed
+ # from Document[].
class Document
class << self
# A nested hash of (const_name, (key, comment)) pairs tracking
# the constant attributes assigned to a constant name.
@@ -134,10 +133,13 @@
end
# Returns the attributes for the specified const_name. If an empty
# const_name ('') is specified, and a default_const_name is set,
# the default_const_name will be used instead.
+ #
+ # Note this method will return ALL attributes associated with const_name,
+ # not just attributes associated with self.
def [](const_name)
const_name = default_const_name if default_const_name && const_name == ''
Document[const_name]
end
@@ -182,11 +184,11 @@
# c.comment # => "this is the comment that is registered"
#
def register___(comment_class=Comment, caller_index=0)
caller[caller_index] =~ CALLER_REGEXP
block = lambda do |scanner, lines|
- n = $3.to_i
+ n = $2.to_i
n += 1 while lines[n] =~ /^\s*(#.*)?$/
n
end
register(block, comment_class)
end
@@ -214,10 +216,10 @@
# parse the comment
comment.parse_down(scanner, lines) do |line|
if line =~ ATTRIBUTE_REGEXP
# rewind to capture the next attribute unless an end is specified.
- scanner.unscan unless $4 == '-' && $3 == key && $1.to_s == const_name
+ scanner.unscan unless $3 == '-' && $2 == key && $1.to_s == const_name
true
else false
end
end