Sha256: 278bf615de36424858af4ee7fd6635b0ff0aab864d84aad4703e04d96ee95d85

Contents?: true

Size: 1.67 KB

Versions: 15

Compression:

Stored size: 1.67 KB

Contents

module MetricFu

  # MetricFu.result memoizes access to a Result object, that will be
  # used throughout the lifecycle of the MetricFu app.
  def self.result
    @result ||= Result.new
  end

  # = Result
  #
  # The Result class is responsible for one thing:
  #
  # It tracks the results generated by each metric used in this test run.
  class Result

    # Renders the result of the result_hash into a yaml serialization
    # ready for writing out to a file.
    #
    # @return YAML
    #   A YAML object containing the results of the result generation
    #   process
    def as_yaml
      result_hash.to_yaml
    end

    def per_file_data
      @per_file_data ||= Hash.new do |hash, filename|
        hash[filename] = Hash.new do |h, line|
          h[line] = Array.new
        end
      end
    end

    def result_hash #:nodoc:
      @result_hash ||= {}
    end

    # Adds a hash from a passed result, produced by one of the Generator
    # classes to the aggregate result_hash managed by this hash.
    #
    # @param result_type Hash
    #   The hash to add to the aggregate result_hash
    def add(result_type)
      mf_debug "result requested #{result_type}"
      metric_options = metric_options_for_result_type(result_type)
      generator_class =  MetricFu::Generator.get_generator(result_type)
      mf_debug "result class found #{generator_class}"
      generator = generator_class.new(metric_options)

      result_hash.merge!(generator.generate_result)

      generator.per_file_info(per_file_data) if generator.respond_to?(:per_file_info)
    end

    private

    def metric_options_for_result_type(result_type)
      MetricFu::Metric.get_metric(result_type).run_options
    end

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
metric_fu-4.11.3 lib/metric_fu/reporting/result.rb
metric_fu-4.11.2 lib/metric_fu/reporting/result.rb
metric_fu-4.11.1 lib/metric_fu/reporting/result.rb
metric_fu-4.11.0 lib/metric_fu/reporting/result.rb
metric_fu-4.10.0 lib/metric_fu/reporting/result.rb
metric_fu-4.9.0 lib/metric_fu/reporting/result.rb
metric_fu-4.8.0 lib/metric_fu/reporting/result.rb
metric_fu-4.7.4 lib/metric_fu/reporting/result.rb
metric_fu-4.7.3 lib/metric_fu/reporting/result.rb
metric_fu-4.7.2 lib/metric_fu/reporting/result.rb
metric_fu-4.7.1 lib/metric_fu/reporting/result.rb
metric_fu-4.7.0 lib/metric_fu/reporting/result.rb
metric_fu-4.6.0 lib/metric_fu/reporting/result.rb
metric_fu-4.5.2 lib/metric_fu/reporting/result.rb
metric_fu-4.5.1 lib/metric_fu/reporting/result.rb