lib/inch/code_object/proxy/base.rb in inch-0.2.2 vs lib/inch/code_object/proxy/base.rb in inch-0.2.3

- old
+ new

@@ -7,14 +7,14 @@ class Base extend Forwardable include NodocHelper # @return [YARD::CodeObjects::Base] the actual (YARD) code object - attr_accessor :object + attr_reader :object # @return [Symbol] - # when objects are assigned to ScoreRanges, this grade is set to + # when objects are assigned to GradeLists, this grade is set to # enable easier querying for objects of a certain grade attr_writer :grade # Tags considered by wrapper methods like {#has_code_example?} CONSIDERED_YARD_TAGS = %w(api example param private return) @@ -25,23 +25,30 @@ # convenient shortcuts to evalution object def_delegators :evaluation, :score, :roles, :priority # @param object [YARD::CodeObjects::Base] the actual (YARD) code object def initialize(object) - self.object = object + @object = object end def api_tag? !api_tag.nil? end def api_tag - object.tag(:api) || (parent && parent.api_tag) + tag(:api) || (parent && parent.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) + nil + end + + # To be overridden + # @see Proxy::NamespaceObject # @return [Array,nil] the children of the current object or +nil+ def children nil end @@ -63,33 +70,33 @@ files.size > 0 ? files[0][0] : nil end # @return [Symbol] def grade - @grade ||= Evaluation.new_score_ranges.detect { |range| - range.range.include?(score) + @grade ||= Evaluation.new_grade_lists.detect { |range| + range.scores.include?(score) }.grade end def has_alias? !object.aliases.empty? end def has_code_example? - !object.tags(:example).empty? || + !tags(:example).empty? || docstring.contains_code_example? end def has_doc? !docstring.empty? end def has_multiple_code_examples? - if object.tags(:example).size > 1 || docstring.code_examples.size > 1 + if tags(:example).size > 1 || docstring.code_examples.size > 1 true else - if tag = object.tag(:example) + if tag = tag(:example) multi_code_examples?(tag.text) elsif text = docstring.code_examples.first multi_code_examples?(text) else false @@ -146,13 +153,17 @@ end # @return [Boolean] # +true+ if the object or its parent is tagged as @private def private_tag? - !object.tag(:private).nil? || (parent && parent.private_tag?) + !private_tag.nil? end + def private_tag + tag(:private) || (parent && parent.private_tag) + end + def private_api_tag? api_tag && api_tag.text == 'private' end def protected? @@ -163,28 +174,40 @@ visibility == :public end # @return [Boolean] +true+ if the object has no documentation at all def undocumented? - docstring.empty? && object.tags.empty? + docstring.empty? && tags.empty? end # @return [Array] # YARD tags that are not already covered by other wrapper methods def unconsidered_tags - @unconsidered_tags ||= object.tags.reject do |tag| + @unconsidered_tags ||= tags.reject do |tag| CONSIDERED_YARD_TAGS.include?(tag.tag_name) end end def inspect "#<#{self.class.to_s}: #{path}>" end - private + protected def multi_code_examples?(text) text.scan(/\b(#{Regexp.escape(name)})[^_0-9\!\?]/m).size > 1 + end + + def tag(name) + tags(name).first + end + + def tags(name = nil) + object.tags(name) + rescue YARD::CodeObjects::ProxyMethodError + # this error is raised by YARD + # see broken.rb in test fixtures + [] end end end end end