Sha256: 1016b01d4cc08836ac7643c28d24698d48ef236145f9cc06e40d8cdfd22e169c

Contents?: true

Size: 1.17 KB

Versions: 75

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

require_relative "ast_traverser"

# :nodoc:
class AstProcessor
  class << self
    def increment(stats, component, arg_name, value)
      stats[component][:arguments][arg_name][value] = 0 unless stats[component][:arguments][arg_name][value]
      stats[component][:arguments][arg_name][value] += 1
    end

    def process_ast(ast, stats)
      traverser = AstTraverser.new
      traverser.walk(ast)

      return if traverser.stats.empty?

      traverser.stats.each do |component, component_info|
        stats[component] ||= {
          paths: []
        }

        stats[component][:paths] << component_info[:path]
        stats[component][:paths].uniq!
        stats[component][:arguments] ||= {}

        component_info[:arguments]&.each do |arg, value|
          arg_name = arg.to_s
          stats[component][:arguments][arg_name] ||= {}

          # we want to count each class separately
          if arg_name == "classes"
            value.split.each do |val|
              increment(stats, component, arg_name, val)
            end
          else
            increment(stats, component, arg_name, value)
          end
        end
      end
    end
  end
end

Version data entries

75 entries across 75 versions & 2 rubygems

Version Path
primer_view_components-0.0.94 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.93 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.92 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.91 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.90 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.89 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.88 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.87 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.86 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.85 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.84 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.83 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.82 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.81 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.80 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.79 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.78 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.77 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.76 lib/tasks/helpers/ast_processor.rb
primer_view_components-0.0.75 lib/tasks/helpers/ast_processor.rb