Commit 33f7f9d2 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Replace #each_member with #all_local_members method.

This way we can either loop or map or reduce over the items as we
wish. Plus the method name is more clear in what it does.

Also added #all_members - method which does the same but includes all
the inherited and mixed in ones.
parent 94209098
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -175,13 +175,26 @@ module JsDuck
      @members_map[type_name ? "#{type_name}-#{name}" : name]
    end

    # Loops through each member of the class, invoking block with each of them
    def each_member(&block)
    # Returns all public members of class, including the inherited and mixed in ones
    def all_members
      all = []
      [:members, :statics].each do |group|
        @doc[group].each_value do |members|
          members.each(&block)
        @doc[group].each_key do |type|
          all += members(type, group)
        end
      end
      all
    end

    # Returns all local public members of class
    def all_local_members
      all = []
      [:members, :statics].each do |group|
        @doc[group].each_value do |ms|
          all += ms.find_all {|m| !m[:private] }
        end
      end
      all
    end

    # A way to access full class name with similar syntax to
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ module JsDuck
    # Performs all inheriting
    def resolve_all
      @relations.each do |cls|
        cls.each_member do |member|
        cls.all_local_members.each do |member|
          if member[:inheritdoc]
            resolve(member)
          end
+2 −2
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ module JsDuck
    def warn_globals
      global = @relations["global"]
      return unless global
      global.each_member do |member|
      global.all_local_members.each do |member|
        warn(:global, "Global #{member[:tagname]}: #{member[:name]}", member)
      end
    end
@@ -71,7 +71,7 @@ module JsDuck

    # Loops through all members of all classes
    def each_member(&block)
      @relations.each {|cls| cls.each_member(&block) }
      @relations.each {|cls| cls.all_local_members.each(&block) }
    end

    # Prints warning + filename and linenumber from doc-context