Class: ArchUnit::Metrics::FluentApi::MetricSelection
- Inherits:
-
Object
- Object
- ArchUnit::Metrics::FluentApi::MetricSelection
- Defined in:
- lib/archunit/metrics/fluentapi/metric_selection.rb
Overview
Lazy selection of one metric over a metrics scope.
Direct Known Subclasses
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
-
#metric ⇒ Object
readonly
Returns the value of attribute metric.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
-
#initialize(scope:, metric:) ⇒ MetricSelection
constructor
A new instance of MetricSelection.
- #measure ⇒ Object
- #should_satisfy(predicate) ⇒ Object
Constructor Details
#initialize(scope:, metric:) ⇒ MetricSelection
Returns a new instance of MetricSelection.
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
#metric ⇒ Object (readonly)
Returns the value of attribute metric.
21 22 23 |
# File 'lib/archunit/metrics/fluentapi/metric_selection.rb', line 21 def metric @metric end |
#scope ⇒ Object (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
#measure ⇒ Object
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 |