Sha256: 4a743d8be42e585bbb62a5bfaa9422dcfe8d04d3e5ba2c78beddbbefc3979ad1

Contents?: true

Size: 1.24 KB

Versions: 22

Compression:

Stored size: 1.24 KB

Contents

require 'jsduck/logger'

module JsDuck

  # Parent class for assets that consist of groups.
  # That is: guides, vides, examples.
  #
  # Subclasses must initialize @groups before calling any of the
  # methods in this class.
  class GroupedAsset
    # Should be called from constructor after @groups have been read in,
    # and after it's been ensured that all items in groupes have names.
    #
    # Prints warning when there is a duplicate item within a group.
    # The warning message should say something like "duplicate <asset type>"
    def build_map_by_name(warning_msg)
      @map_by_name = {}
      @groups.each do |group|
        group_map = {}
        group["items"].each do |item|
          if group_map[item["name"]]
            Logger.instance.warn(:dup_asset, "#{warning_msg} '#{item['name']}'")
          end
          @map_by_name[item["name"]] = item
          group_map[item["name"]] = item
        end
      end
    end

    # Accesses item by name
    def [](name)
      @map_by_name[name]
    end

    # Iterates over all items in all groups
    def each_item
      @groups.each do |group|
        group["items"].each {|item| yield item }
      end
    end

    # Returns all groups as array
    def to_array
      @groups
    end
  end

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
jsduck-3.11.2 lib/jsduck/grouped_asset.rb
jsduck-4.0.beta2 lib/jsduck/grouped_asset.rb
jsduck-3.11.1 lib/jsduck/grouped_asset.rb
jsduck-4.0.beta lib/jsduck/grouped_asset.rb
jsduck-3.11.0 lib/jsduck/grouped_asset.rb
jsduck-3.10.5 lib/jsduck/grouped_asset.rb
jsduck-3.10.4 lib/jsduck/grouped_asset.rb
jsduck-3.10.3 lib/jsduck/grouped_asset.rb
jsduck-3.10.2 lib/jsduck/grouped_asset.rb
jsduck-3.10.1 lib/jsduck/grouped_asset.rb
jsduck-3.10.0 lib/jsduck/grouped_asset.rb
jsduck-3.9.1 lib/jsduck/grouped_asset.rb
jsduck-3.9.0 lib/jsduck/grouped_asset.rb
jsduck-3.9.0.pre lib/jsduck/grouped_asset.rb
jsduck-3.8.4 lib/jsduck/grouped_asset.rb
jsduck-3.8.3 lib/jsduck/grouped_asset.rb
jsduck-3.8.2 lib/jsduck/grouped_asset.rb
jsduck-3.8.1 lib/jsduck/grouped_asset.rb
jsduck-3.8.0 lib/jsduck/grouped_asset.rb
jsduck-3.7.0 lib/jsduck/grouped_asset.rb