Sha256: dd2c5ad2282fab33b6ea96d350bd31b20569a31264c155f719fc290e9b15f1e8

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

module Hexx
  module Suit
    module Metrics

      # Prepares and runs yardstick environment from '.hexx-suit.yml'
      class Yardstick < RSpec::Metrics::Base

        # Loads yardstick verifier
        #
        # @return [Hexx::Suit::Metrics::Yardstick]
        #
        # @api private
        def self.new
          require "yardstick/rake/measurement"
          super
        end

        # @!scope class
        # Prepares output for the yardstick and sets the YARDSTICK_OUTPUT env
        #
        # @return [self]
        def load
          prepare_output
          set_environment

          super
        end

        # @!scope class
        # Runs yardstick with options from '.hexx-suit.yml'
        #
        # @return [undefined]
        def run
          measurement.yardstick_measure
        end

        private

        # yardstic metric definitions

        def name
          "yardstick"
        end

        def default_options
          {
            "output" => "tmp/yardstick/output.log",
            "path"   => "lib/**/*.rb"
          }
        end

        def metric
          ::Yardstick::Rake::Measurement
        end

        # operations

        def prepare_output
          Hexx::RSpec["mkdir #{::File.dirname(output)} -p"]
          Hexx::RSpec["touch #{output}"]
        end

        def set_environment
          ENV["YARDSTICK_OUTPUT"] = output
        end

        # helpers

        def measurement
          metric.new(:yardstick_measure, options) do |config|
            config.output = output
          end
        end

        def options
          @options ||= begin
            list = default_options.merge settings.to_hash
            list["path"] = Array(list["path"]).join(" ")
            list
          end
        end

        def output
          @output ||= options["output"]
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hexx-suit-2.3.2 lib/hexx/suit/metrics/yardstick.rb
hexx-suit-2.3.0 lib/hexx/suit/metrics/yardstick.rb