Sha256: dba08a6d8466ac9cb69a7504040dea2d6305d8076695bb568cb880a56dea3455

Contents?: true

Size: 1.83 KB

Versions: 10

Compression:

Stored size: 1.83 KB

Contents

# encoding: utf-8

module Hexx

  module RSpec

    module Metrics

      # Base class for metrics configurators
      #
      # To be used by the 'hexx-suit' module as well
      class Base

        # The utility class for sending commands to the system
        SYSTEM = System

        # Loads metric settings and configures the current metric
        #
        # @return [Hexx::RSpec::Metrics]
        #   the configured metric object
        def self.load
          __send__(:new).load
        end

        # Configures and runs the current metric
        #
        # @return (see #run)
        def self.run
          load.run
        end

        # Loads the configuration file and configures the metric
        #
        # @return [self]
        #
        # @api private
        def load
          self
        end

        # Runs the metric
        #
        # @abstract
        #
        # @return [undefined]
        #
        # @api private
        def run; end

        # @note
        #   The class has a private constructor.
        #   Use methods {.load} or {.run}.
        private_class_method :new

        private

        # Extracts a hash of settings from the current file
        #
        # @return [Hash]
        #
        # @api private
        def settings
          @settings ||= file ? YAML.load_file(file) : {}
        end

        # Returns the name of the settings file
        #
        # @return [String]
        #   when the file is present in the config/metrics folder
        # @return [nil]
        #   when the file is absent in the config/metrics folder
        #
        # @api private
        def file
          @file ||= Dir["config/metrics/#{ name }.yml"].first
        end

        # The name of the current metric
        #
        # @abstract
        #
        # @return [Symbol]
        attr_reader :name
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hexx-rspec-0.4.2 lib/hexx/rspec/metrics/base.rb
hexx-rspec-0.4.1 lib/hexx/rspec/metrics/base.rb
hexx-rspec-0.4.0 lib/hexx/rspec/metrics/base.rb
hexx-rspec-0.3.1 lib/hexx/rspec/metrics/base.rb
hexx-rspec-0.3.0 lib/hexx/rspec/metrics/base.rb
hexx-rspec-0.2.2 lib/hexx/rspec/metrics/base.rb
hexx-rspec-0.2.1 lib/hexx/rspec/metrics/base.rb
hexx-rspec-0.2.0 lib/hexx/rspec/metrics/base.rb
hexx-rspec-0.1.0 lib/hexx/rspec/metrics/base.rb
hexx-rspec-0.0.1 lib/hexx/rspec/metrics/base.rb