Commit 43bcbaec authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Ignore hidden members when counting new ones.

The Class#find_members(:local=>true) previously also returned
the hidden members.  This resulted from the fact that internally
it was using #global_by_id and #local_by_id indexes from MembersIndex
class.  As these maps are also used internally inside MembersIndex
I'm now exposing #all_global and #all_local methods which return
the arrays instead of hashes and both without any hidden members.
parent 5e1c2820
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -152,9 +152,9 @@ module JsDuck
        ms = @members_index.global_by_name[query[:name]] || []
        ms = ms.find_all {|m| m[:owner] == @doc[:name]} if query[:local]
      elsif query[:local]
        ms = @members_index.local_by_id.values
        ms = @members_index.all_local
      else
        ms = @members_index.global_by_id.values
        ms = @members_index.all_global
      end

      if query[:tagname]
+24 −12
Original line number Diff line number Diff line
@@ -31,6 +31,30 @@ module JsDuck
      @global_map_by_name
    end

    # Returns array of all members (including inherited ones)
    def all_global
      global_by_id.values
    end

    # Returns array of all local members (excludes inherited ones)
    def all_local
      local_by_id.values.reject {|m| m[:meta] && m[:meta][:hide] }
    end

    # Clears the search cache.
    # Using this is REALLY BAD - try to get rid of it.
    def invalidate!
      @map_by_id = nil
      @global_map_by_id = nil
      @global_map_by_name = nil

      @cls.parent.members_index.invalidate! if @cls.parent

      @cls.mixins.each {|mix| mix.members_index.invalidate! }
    end

    protected

    # Returns hash of all members by ID (including inherited ones)
    def global_by_id
      unless @global_map_by_id
@@ -64,18 +88,6 @@ module JsDuck
      @map_by_id
    end

    # Clears the search cache.
    # Using this is REALLY BAD - try to get rid of it.
    def invalidate!
      @map_by_id = nil
      @global_map_by_id = nil
      @global_map_by_name = nil

      @cls.parent.members_index.invalidate! if @cls.parent

      @cls.mixins.each {|mix| mix.members_index.invalidate! }
    end

    private

    # merges second members hash into first one