lib/inch/language/nodejs/provider/jsdoc/object/base.rb in inch-0.5.0.rc5 vs lib/inch/language/nodejs/provider/jsdoc/object/base.rb in inch-0.5.0.rc6

- old
+ new

@@ -1,187 +1,224 @@ +require 'inch/language/nodejs/provider/jsdoc/docstring' +require 'inch/utils/code_location' + module Inch module Language module Nodejs module Provider module JSDoc module Object # @abstract class Base + # @return [String] the codebase's directory + attr_accessor :base_dir + # @param hash [Hash] hash returned via JSON interface def initialize(hash) @hash = hash end def name - raise NotImplementedError + @hash['name'] end def fullname - raise NotImplementedError + #fail NotImplementedError + base = "#{@hash['longname']}" + if meta? + base << " @ #{meta['path']}/" \ + "#{meta['filename']}:" \ + "#{meta['lineno']}" + end + base end + # Returns all files declaring the object in the form of an Array + # of Arrays containing the location of their declaration. + # + # @return [Array<CodeLocation>] def files - raise NotImplementedError + return [] unless meta? + filename = meta['path'] + '/' + meta['filename'] + [ + Inch::Utils::CodeLocation.new('', filename, meta['lineno']) + ] end def filename - raise NotImplementedError + files.first.filename unless files.empty? end + attr_writer :children_fullnames def children_fullnames - raise NotImplementedError + @children_fullnames ||= [] end def parent_fullname - raise NotImplementedError + if depth == 1 + nil + else + fullname.split('.')[0...-1].join('.') + end end def api_tag? - raise NotImplementedError + nil end def aliased_object_fullname - raise NotImplementedError + nil end def aliases_fullnames - raise NotImplementedError + nil end def attributes - raise NotImplementedError + [] end def bang_name? - raise NotImplementedError + false end def constant? - raise NotImplementedError + false # raise NotImplementedError end def constructor? - raise NotImplementedError + false end def depth - raise NotImplementedError + fullname.split('.').size end + # @return [Docstring] def docstring - raise NotImplementedError + @docstring ||= Docstring.new(@hash['comment']) end def getter? - raise NotImplementedError + name =~ /^get_/ # raise NotImplementedError end def has_children? - raise NotImplementedError + !children_fullnames.empty? end def has_code_example? - raise NotImplementedError + false # raise NotImplementedError end def has_doc? - raise NotImplementedError + !undocumented? end def has_multiple_code_examples? - raise NotImplementedError + false # raise NotImplementedError end def has_unconsidered_tags? - raise NotImplementedError + false # raise NotImplementedError end def method? - raise NotImplementedError + false end def nodoc? - raise NotImplementedError + @hash['comment'] == false end def namespace? - raise NotImplementedError + false end def original_docstring - raise NotImplementedError + @hash['comment'] end def overridden? - raise NotImplementedError + false # raise NotImplementedError end def overridden_method_fullname - raise NotImplementedError + nil # raise NotImplementedError end def parameters - raise NotImplementedError + [] # raise NotImplementedError end def private? - raise NotImplementedError + false end def tagged_as_internal_api? - raise NotImplementedError + false end def tagged_as_private? - raise NotImplementedError + nodoc? end def protected? - raise NotImplementedError + false end def public? - raise NotImplementedError + true end def questioning_name? - raise NotImplementedError + fullname =~ /\?$/ end def return_described? - raise NotImplementedError + false # raise NotImplementedError end def return_mentioned? - raise NotImplementedError + false # raise NotImplementedError end def return_typed? - raise NotImplementedError + false # raise NotImplementedError end def in_root? - raise NotImplementedError + depth == 1 end def setter? - raise NotImplementedError + name =~ /^set_/ # raise NotImplementedError end def source - raise NotImplementedError + nil end def unconsidered_tag_count - raise NotImplementedError + 0 end def undocumented? - raise NotImplementedError + @hash['comment'].to_s.empty? end def visibility - raise NotImplementedError + :public + end + + protected + + def meta? + !meta.nil? + end + + def meta + @hash['meta'] end end end end end