lib/yard/code_objects/base.rb in yard-0.6.4 vs lib/yard/code_objects/base.rb in yard-0.6.5
- old
+ new
@@ -150,23 +150,25 @@
# Is the object defined conditionally at runtime?
# @see #dynamic
def dynamic?; @dynamic end
- # This attribute exists in order to maintain a consistent interface
- # with the {MethodObject} class, so that a {Verifier} expression need
- # not check the object type before accessing visibility.
- #
- # @return [Symbol] always returns public for a base object.
- def visibility; :public end
+ # @return [Symbol] the visibility of an object (:public, :private, :protected)
+ attr_accessor :visibility
+ undef visibility=
+ def visibility=(v) @visibility = v.to_sym end
class << self
# Allocates a new code object
# @return [Base]
# @see #initialize
def new(namespace, name, *args, &block)
raise ArgumentError, "invalid empty object name" if name.to_s.empty?
+ if namespace.is_a?(ConstantObject)
+ namespace = Proxy.new(namespace.namespace, namespace.value)
+ end
+
if name.to_s[0,2] == NSEP
name = name.to_s[2..-1]
namespace = Registry.root
elsif name =~ /(?:#{NSEPQ}|#{ISEPQ}|#{CSEPQ})([^#{NSEPQ}#{ISEPQ}#{CSEPQ}]+)$/
return new(Proxy.new(namespace, $`), $1, *args, &block)
@@ -210,10 +212,11 @@
@files = []
@current_file_has_comments = false
@name = name.to_sym
@source_type = :ruby
+ @visibility = :public
@tags = []
@docstring = Docstring.new('', self)
@namespace = nil
self.namespace = namespace
yield(self) if block_given?
@@ -351,18 +354,18 @@
@docstring
end
@docstring_extra ? value + @docstring_extra : value
end
- # Attaches a docstring to a code oject by parsing the comments attached to the statement
+ # Attaches a docstring to a code object by parsing the comments attached to the statement
# and filling the {#tags} and {#docstring} methods with the parsed information.
#
# @param [String, Array<String>, Docstring] comments
# the comments attached to the code object to be parsed
# into a docstring and meta tags.
def docstring=(comments)
- if comments =~ /^\s*\(see (\S+)\s*\)(?:\s|$)/
+ if comments =~ /\A\s*\(see (\S+)\s*\)(?:\s|$)/
path, extra = $1, $'
@docstring_extra = extra.empty? ? nil : Docstring.new(extra, self)
@docstring = Proxy.new(namespace, path)
else
@docstring_extra = nil
@@ -408,10 +411,15 @@
end
return other unless namespace
common = [path, other].join(" ").match(/^(\S*)\S*(?: \1\S*)*$/)[1]
common = path unless common =~ /(\.|::|#)$/
common = common.sub(/(\.|::|#)[^:#\.]*?$/, '') if same_parent
- result = other.sub(/^#{Regexp.quote common}(::|\.|)?/, '')
+ if %w(. :).include?(common[-1,1]) || other[common.size,1] == '#'
+ suffix = ''
+ else
+ suffix = '(::|\.)'
+ end
+ result = other.sub(/^#{Regexp.quote common}#{suffix}/, '')
result.empty? ? other : result
end
# Renders the object using the {Templates::Engine templating system}.
#