Class: ArchUnit::Metrics::FluentApi::MetricSelection

Inherits:
Object
  • Object
show all
Defined in:
lib/archunit/metrics/fluentapi/metric_selection.rb

Overview

Lazy selection of one metric over a metrics scope.

Direct Known Subclasses

CustomMetricBuilder

Constant Summary collapse

THRESHOLD_METHODS =
{
  should_be_below: :below,
  should_be_above: :above,
  should_be: :equal,
  should_be_below_or_equal: :below_or_equal,
  should_be_above_or_equal: :above_or_equal
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope:, metric:) ⇒ MetricSelection

Returns a new instance of MetricSelection.

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
# File 'lib/archunit/metrics/fluentapi/metric_selection.rb', line 23

def initialize(scope:, metric:)
  raise ArgumentError, 'scope must be a MetricsBuilder' unless scope.is_a?(MetricsBuilder)
  raise ArgumentError, 'metric must be a Metric' unless metric.is_a?(Calculation::Metric)

  @scope = scope
  @metric = metric
  freeze
end

Instance Attribute Details

#metricObject (readonly)

Returns the value of attribute metric.



21
22
23
# File 'lib/archunit/metrics/fluentapi/metric_selection.rb', line 21

def metric
  @metric
end

#scopeObject (readonly)

Returns the value of attribute scope.



21
22
23
# File 'lib/archunit/metrics/fluentapi/metric_selection.rb', line 21

def scope
  @scope
end

Instance Method Details

#measureObject



32
33
34
35
36
37
38
39
40
# File 'lib/archunit/metrics/fluentapi/metric_selection.rb', line 32

def measure
  scope.__send__(:subjects_for, metric.subject_type).map do |subject|
    MetricMeasurement.new(
      subject:,
      metric_name: metric.name,
      value: metric.calculate(subject)
    )
  end.freeze
end

#should_satisfy(predicate) ⇒ Object



48
49
50
# File 'lib/archunit/metrics/fluentapi/metric_selection.rb', line 48

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