lib/inch/code_object/provider/yard/object/base.rb in inch-0.4.10 vs lib/inch/code_object/provider/yard/object/base.rb in inch-0.5.0.rc1

- old
+ new

@@ -1,6 +1,6 @@ -require "forwardable" +require 'forwardable' module Inch module CodeObject module Provider module YARD @@ -19,21 +19,18 @@ # Tags considered by wrapper methods like {#has_code_example?} CONSIDERED_YARD_TAGS = %w(api example param private return since) AUTO_GENERATED_TAG_NAMES = %w(raise yield) # convenient shortcuts to (YARD) code object - def_delegators :object, - :type, :namespace, :source, :source_type, :group, - :dynamic, :visibility + def_delegators :object, :type, :namespace, :source, :source_type, :group, :dynamic, :visibility - # @param object [YARD::CodeObjects::Base] the actual (YARD) code - # object + # @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 + @__api_tag = __api_tag + @__parent = __parent + @__private_tag = __private_tag end # Returns the fullname of the object that the current object # is an alias for attr_accessor :aliased_object_fullname @@ -46,55 +43,34 @@ def api_tag? !api_tag.nil? end - attr_reader :api_tag + def api_tag + @__api_tag + end # To be overridden # @see Proxy::NamespaceObject - # @return [CodeObject::Proxy::Base,nil] the child inside the current - # object or +nil+ - def child(_name) + # @return [CodeObject::Proxy::Base,nil] the child inside the current object or +nil+ + def child(name) nil end - # @return [Array,nil] the full names of the children of the current - # object + # @return [Array,nil] the full names of the children of the current object def children_fullnames [] end # To be overridden # @see Proxy::NamespaceObject def children [] end - RUBY_CORE = %w( - Array Bignum BasicObject Object Module Class Complex NilClass - Numeric String Float Fiber FiberError Continuation Dir File - Encoding Enumerator StopIteration Enumerator::Generator - Enumerator::Yielder Exception SystemExit SignalException Interrupt - StandardError TypeError ArgumentError IndexError KeyError - RangeError ScriptError SyntaxError LoadError NotImplementedError - NameError NoMethodError RuntimeError SecurityError NoMemoryError - EncodingError SystemCallError Encoding::CompatibilityError - File::Stat IO Hash ENV IOError EOFError ARGF RubyVM - RubyVM::InstructionSequence Math::DomainError ZeroDivisionError - FloatDomainError Integer Fixnum Data TrueClass FalseClass Mutex - Thread Proc LocalJumpError SystemStackError Method UnboundMethod - Binding Process::Status Random Range Rational RegexpError Regexp - MatchData Symbol Struct ThreadGroup ThreadError Time - Encoding::UndefinedConversionError - Encoding::InvalidByteSequenceError - Encoding::ConverterNotFoundError Encoding::Converter RubyVM::Env - - Comparable Kernel File::Constants Enumerable Errno FileTest GC - ObjectSpace GC::Profiler IO::WaitReadable IO::WaitWritable Marshal - Math Process Process::UID Process::GID Process::Sys Signal - ) + RUBY_CORE = %w(Array Bignum BasicObject Object Module Class Complex NilClass Numeric String Float Fiber FiberError Continuation Dir File Encoding Enumerator StopIteration Enumerator::Generator Enumerator::Yielder Exception SystemExit SignalException Interrupt StandardError TypeError ArgumentError IndexError KeyError RangeError ScriptError SyntaxError LoadError NotImplementedError NameError NoMethodError RuntimeError SecurityError NoMemoryError EncodingError SystemCallError Encoding::CompatibilityError File::Stat IO Hash ENV IOError EOFError ARGF RubyVM RubyVM::InstructionSequence Math::DomainError ZeroDivisionError FloatDomainError Integer Fixnum Data TrueClass FalseClass Mutex Thread Proc LocalJumpError SystemStackError Method UnboundMethod Binding Process::Status Random Range Rational RegexpError Regexp MatchData Symbol Struct ThreadGroup ThreadError Time Encoding::UndefinedConversionError Encoding::InvalidByteSequenceError Encoding::ConverterNotFoundError Encoding::Converter RubyVM::Env) + + %w(Comparable Kernel File::Constants Enumerable Errno FileTest GC ObjectSpace GC::Profiler IO::WaitReadable IO::WaitWritable Marshal Math Process Process::UID Process::GID Process::Sys Signal) def core? RUBY_CORE.include?(name.to_s) end # @return [Docstring] @@ -114,12 +90,11 @@ # this error is raised by YARD # see broken.rb in test fixtures [] end - # CodeLocation is a utility class to find declarations of objects in - # files + # CodeLocation is a utility class to find declarations of objects in files class CodeLocation < Struct.new(:base_dir, :relative_path, :line_no) def filename File.join(base_dir, relative_path) end end @@ -155,13 +130,13 @@ def has_multiple_code_examples? if tags(:example).size > 1 || docstring.code_examples.size > 1 true else - if (tag = tag(:example)) + if tag = tag(:example) multi_code_examples?(tag.text) - elsif (text = docstring.code_examples.first) + elsif text = docstring.code_examples.first multi_code_examples?(text) else false end end @@ -209,11 +184,13 @@ def parameters [] end # @return [Array,nil] the parent of the current object or +nil+ - attr_reader :parent + def parent + @__parent + end def __parent YARD::Object.for(object.parent) if object.parent end @@ -249,11 +226,11 @@ def unconsidered_tag_count unconsidered_tags.size end def inspect - "#<#{self.class}: #{fullname}>" + "#<#{self.class.to_s}: #{fullname}>" end protected def multi_code_examples?(text) @@ -264,14 +241,16 @@ # +true+ if the object or its parent is tagged as @private def private_tag? !private_tag.nil? end - attr_reader :private_tag + def private_tag + @__private_tag + end def private_api_tag? - api_tag && api_tag.text == "private" + api_tag && api_tag.text == 'private' end def tag(name) tags(name).first end @@ -288,15 +267,15 @@ # YARD tags that are not already covered by other wrapper methods def unconsidered_tags @unconsidered_tags ||= tags.reject do |tag| auto_generated_tag?(tag) || CONSIDERED_YARD_TAGS.include?(tag.tag_name) - end + end end def __depth(i = 0) if parent - parent.__depth(i + 1) + parent.__depth(i+1) else i end end