Class: ArchUnit::Metrics::FluentApi::CustomMetricBuilder

Inherits:
MetricSelection show all
Defined in:
lib/archunit/metrics/fluentapi/custom_metric_builder.rb

Overview

A user-defined class calculation that can be measured or asserted.

Constant Summary

Constants inherited from MetricSelection

MetricSelection::THRESHOLD_METHODS

Instance Attribute Summary

Attributes inherited from MetricSelection

#metric, #scope

Instance Method Summary collapse

Methods inherited from MetricSelection

#measure

Constructor Details

#initialize(scope:, name:, description:, calculation:) ⇒ CustomMetricBuilder

Returns a new instance of CustomMetricBuilder.



13
14
15
16
17
18
19
20
21
22
# File 'lib/archunit/metrics/fluentapi/custom_metric_builder.rb', line 13

def initialize(scope:, name:, description:, calculation:)
  unless name.is_a?(String) && !name.empty?
    raise ArgumentError, 'custom metric name must be a non-empty String'
  end

  metric = Calculation::Metric.new(
    name:, description:, subject_type: Extraction::ClassInfo, calculation:
  )
  super(scope:, metric:)
end

Instance Method Details

#should_satisfy(predicate) ⇒ Object



24
25
26
# File 'lib/archunit/metrics/fluentapi/custom_metric_builder.rb', line 24

def should_satisfy(predicate)
  CustomMetricCondition.new(selection: self, predicate:)
end