lib/yard/code_objects/base.rb in yard-0.4.0 vs lib/yard/code_objects/base.rb in yard-0.5.0
- old
+ new
@@ -34,11 +34,11 @@
ISEPQ = ISEP
CSEP = '.'
CSEPQ = Regexp.quote CSEP
CONSTANTMATCH = /[A-Z]\w*/
NAMESPACEMATCH = /(?:(?:#{NSEPQ})?#{CONSTANTMATCH})+/
- METHODNAMEMATCH = /[a-zA-Z_]\w*[!?=]?|[-+~]\@|<<|>>|=~|===?|[<>]=?|\*\*|[-\/+%^&*~`|]|\[\]=?/
+ METHODNAMEMATCH = /[a-zA-Z_]\w*[!?=]?|[-+~]\@|<<|>>|=~|===?|<=>|[<>]=?|\*\*|[-\/+%^&*~`|]|\[\]=?/
METHODMATCH = /(?:(?:#{NAMESPACEMATCH}|self)\s*(?:#{CSEPQ}|#{NSEPQ})\s*)?#{METHODNAMEMATCH}/
BUILTIN_EXCEPTIONS = ["SecurityError", "Exception", "NoMethodError", "FloatDomainError",
"IOError", "TypeError", "NotImplementedError", "SystemExit", "Interrupt", "SyntaxError",
"RangeError", "NoMemoryError", "ArgumentError", "ThreadError", "EOFError", "RuntimeError",
@@ -97,10 +97,16 @@
# The source code associated with the object
# @return [String, nil] source, if present, or nil
attr_accessor :source
+ # Language of the source code associated with the object. Defaults to
+ # +:ruby+.
+ #
+ # @return [Symbol] the language type
+ attr_accessor :source_type
+
# The one line signature representing an object. For a method, this will
# be of the form "def meth(arguments...)". This is usually the first
# source line.
#
# @return [String] a line of source
@@ -155,11 +161,11 @@
# Compares the class with subclasses
#
# @param [Object] other the other object to compare classes with
# @return [Boolean] true if other is a subclass of self
def ===(other)
- self >= other.class ? true : false
+ other.is_a?(self)
end
end
# Creates a new code object
#
@@ -182,10 +188,11 @@
end
@files = []
@current_file_has_comments = false
@name = name.to_sym
+ @source_type = :ruby
@tags = []
@docstring = Docstring.new('', self)
self.namespace = namespace
yield(self) if block_given?
end
@@ -260,11 +267,11 @@
end
# Sets a custom attribute on the object
# @param [#to_s] key the name of the custom attribute
# @param [Object] value the value to associate
- # @return [nil]
+ # @return [void]
# @see #[]
def []=(key, value)
if respond_to?("#{key}=")
send("#{key}=", value)
else
@@ -329,11 +336,11 @@
# @example The path of an instance method
# MethodObject.new(P("A::B"), :c).path # => "A::B#c"
# @return [String] the unique path of the object
# @see #sep
def path
- if parent && parent != Registry.root
+ if parent && !parent.root?
[parent.path, name.to_s].join(sep)
else
name.to_s
end
end
@@ -394,10 +401,13 @@
def tags(name = nil); @docstring.tags(name) end
# Tests if the {#docstring} has a tag
# @see Docstring#has_tag?
def has_tag?(name); @docstring.has_tag?(name) end
+
+ # @return whether or not this object is a RootObject
+ def root?; false end
protected
# Override this method with a custom component separator. For instance,
# {MethodObject} implements sep as '#' or '.' (depending on if the
@@ -412,10 +422,11 @@
#
# @param [String] source the source code to format
# @return [String] formatted source
def format_source(source)
source.chomp!
- indent = source.split(/\r?\n/).last[/^([ \t]*)/, 1].length
+ last = source.split(/\r?\n/).last
+ indent = last ? last[/^([ \t]*)/, 1].length : 0
source.gsub(/^[ \t]{#{indent}}/, '')
end
end
end
end