Sha256: 7c33302b12a04a67b33abccb1a11c2e6d0393b150b011c9e9c52d78f56b3e521

Contents?: true

Size: 1.17 KB

Versions: 246

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

246 entries across 246 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.45-x64-mingw-ucrt lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.45 lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.45-x86_64-darwin lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.45-arm64-darwin lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.45-x86_64-linux lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.45-aarch64-linux lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.44-aarch64-linux lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.44-arm64-darwin lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.44-x86_64-linux lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.44-x86_64-darwin lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.44-x64-mingw-ucrt lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.44 lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.43-x64-mingw-ucrt lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.43-arm64-darwin lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.43-x86_64-linux lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.43-x86_64-darwin lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.43-aarch64-linux lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.43 lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.42-x86_64-linux lib/tasks/helpers/ast_processor.rb
ariadne_view_components-0.0.42-arm64-darwin lib/tasks/helpers/ast_processor.rb