Class: MetricFu::Configuration

Inherits:
Object
  • Object
show all
Includes:
Environment
Defined in:
lib/metric_fu/configuration.rb

Overview

Configuration

The Configuration class, as it sounds, provides methods for configuring the behaviour of MetricFu.

Customization for CruiseControl.rb

The Configuration class checks for the presence of a 'CC_BUILD_ARTIFACTS' environment variable. If it's found it will change the default output directory from the default “tmp/metric_fu to the directory represented by 'CC_BUILD_ARTIFACTS'

Metric Configuration

Each metric can be configured by e.g.

config.configure_metric(:flog) do |flog|
  flog.enable
  flog.dirs_to_flog = %w(app lib spec)
  ...
end

or iterate over all metrics to configure by e.g.

config.configure_metrics.each do |metric|
  ...
end

Formatter Configuration

Formatters can be configured by e.g.

config.configure_formatter(:html)
config.configure_formatter(:yaml, "customreport.yml")
config.configure_formatter(MyCustomFormatter)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Environment

#debug_info, #environment_details, #is_cruise_control_rb?, #jruby?, #library_details, #mri?, #osx?, #platform, #rails?, #rubinius?, #ruby18?, #ruby192?, #ruby_details, #ruby_flavor, ruby_strangely_makes_accessors_private?, #ruby_version, #supports_ripper?, #verbose, #verbose=, #version

Constructor Details

#initializeConfiguration

:nodoc:#


59
60
61
# File 'lib/metric_fu/configuration.rb', line 59

def initialize #:nodoc:#
  reset
end

Instance Attribute Details

#formattersObject (readonly)

TODO review if these code is functionally duplicated in the base generator initialize


65
66
67
# File 'lib/metric_fu/configuration.rb', line 65

def formatters
  @formatters
end

Class Method Details

.configure_metric(name) {|MetricFu::Metric.get_metric(name)| ... } ⇒ Object

Yields:


93
94
95
# File 'lib/metric_fu/configuration.rb', line 93

def self.configure_metric(name)
  yield MetricFu::Metric.get_metric(name)
end

.run {|MetricFu.configuration| ... } ⇒ Object

This allows us to have a nice syntax like:

MetricFu.run do |config|
  config.configure_metric(:churn) do
    ...
  end

  config.configure_formatter(MyCustomFormatter)
end

See the README for more information on configuration options. TODO: Consider breaking compatibility by removing this, now unused method


89
90
91
# File 'lib/metric_fu/configuration.rb', line 89

def self.run
  yield MetricFu.configuration
end

Instance Method Details

#configure_formatter(format, output = nil) ⇒ Object

TODO: Reconsider method name/behavior, as it really adds a formatter


115
116
117
# File 'lib/metric_fu/configuration.rb', line 115

def configure_formatter(format, output = nil)
  @formatters << MetricFu::Formatter.class_for(format).new(output: output)
end

#configure_graph_engine(graph_engine) ⇒ Object


125
126
127
# File 'lib/metric_fu/configuration.rb', line 125

def configure_graph_engine(graph_engine)
  @graph_engine = graph_engine
end

#configure_metric(name, &block) ⇒ Object


97
98
99
# File 'lib/metric_fu/configuration.rb', line 97

def configure_metric(name, &block)
  self.class.configure_metric(name, &block)
end

#configure_metricsObject


101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/metric_fu/configuration.rb', line 101

def configure_metrics
  MetricFu::Io::FileSystem.set_directories
  MetricFu::Metric.metrics.each do |metric|
    if block_given?
      yield metric
    else
      metric.enabled = false
      metric.enable
    end
    metric.activate if metric.enabled unless metric.activated
  end
end

#graph_engineObject


129
130
131
# File 'lib/metric_fu/configuration.rb', line 129

def graph_engine
  @graph_engine
end

#graphed_metricsArray<Symbol>

Returns names of enabled metrics with graphs.

Returns:

  • (Array<Symbol>)

    names of enabled metrics with graphs


120
121
122
123
# File 'lib/metric_fu/configuration.rb', line 120

def graphed_metrics
  # TODO: This is a common enough need to be pushed into MetricFu::Metric as :enabled_metrics_with_graphs
  MetricFu::Metric.enabled_metrics.select(&:has_graph?).map(&:name)
end

#resetObject


66
67
68
69
70
71
72
73
74
75
# File 'lib/metric_fu/configuration.rb', line 66

def reset
  # TODO: Remove calls to self and/or allow querying the
  #   template/filesystem/metric/graph/environment, etc settings
  #   from the configuration instance
  MetricFu::Io::FileSystem.set_directories
  @templates_configuration = MetricFu::Templates::Configuration.new
  MetricFu::Formatter::Templates.templates_configuration = @templates_configuration
  @formatters = []
  @graph_engine = :bluff
end

#templates_configuration {|@templates_configuration| ... } ⇒ Object

This allows us to configure the templates with:

MetricFu.run do |config|
  config.templates_configuration do |templates_config|
    templates_config.link_prefix = 'http:/'
  end
end

140
141
142
# File 'lib/metric_fu/configuration.rb', line 140

def templates_configuration
  yield @templates_configuration
end

#templates_option(option) ⇒ String

Returns the configured template option.

Parameters:

  • option (String, Symbol)

    the requested template option

Returns:

  • (String)

    the configured template option


146
147
148
# File 'lib/metric_fu/configuration.rb', line 146

def templates_option(option)
  @templates_configuration.option(option)
end