lib/inch/code_object/provider/yard/object/base.rb in inch-0.3.0 vs lib/inch/code_object/provider/yard/object/base.rb in inch-0.3.1.rc1
- old
+ new
@@ -23,18 +23,21 @@
def_delegators :object, :type, :namespace, :source, :source_type, :signature, :group, :dynamic, :visibility
# @param object [YARD::CodeObjects::Base] the actual (YARD) code object
def initialize(object)
@object = object
+ @__api_tag = __api_tag
+ @__parent = __parent
+ @__private_tag = __private_tag
end
def api_tag?
!api_tag.nil?
end
def api_tag
- tag(:api) || (parent && parent.api_tag)
+ @__api_tag
end
# To be overridden
# @see Proxy::NamespaceObject
# @return [CodeObject::Proxy::Base,nil] the child inside the current object or +nil+
@@ -98,15 +101,15 @@
# is first declared)
files.first && files.first.filename
end
def fullname
- object.path
+ @fullname ||= object.path
end
def name
- object.name
+ @name ||= object.name
end
def has_alias?
false
end
@@ -155,18 +158,13 @@
# +depth+ answers the question "how many layers of code objects are
# above this one?"
#
# @note top-level counts, that's why Foo has depth 1!
#
- # @param i [Fixnum] a counter for recursive method calls
# @return [Fixnum] the depth of the object in terms of namespace
- def depth(i = 0)
- if parent
- parent.depth(i+1)
- else
- i
- end
+ def depth
+ @__depth ||= __depth
end
# @return [Boolean] +true+ if the object represents a method
def method?
false
@@ -181,10 +179,14 @@
[]
end
# @return [Array,nil] the parent of the current object or +nil+
def parent
+ @__parent
+ end
+
+ def __parent
YARD::Object.for(object.parent) if object.parent
end
def private?
visibility == :private
@@ -195,11 +197,11 @@
def private_tag?
!private_tag.nil?
end
def private_tag
- tag(:private) || (parent && parent.private_tag)
+ @__private_tag
end
def private_api_tag?
api_tag && api_tag.text == 'private'
end
@@ -252,9 +254,28 @@
def unconsidered_tags
@unconsidered_tags ||= tags.reject do |tag|
CONSIDERED_YARD_TAGS.include?(tag.tag_name)
end
end
+
+ def __depth(i = 0)
+ if parent
+ parent.__depth(i+1)
+ else
+ i
+ end
+ end
+
+ private
+
+ def __api_tag
+ tag(:api) || (parent && parent.api_tag)
+ end
+
+ def __private_tag
+ tag(:private) || (parent && parent.private_tag)
+ end
+
end
end
end
end
end