Class: ArchUnit::Metrics::Calculation::Metric
- Inherits:
-
Data
- Object
- Data
- ArchUnit::Metrics::Calculation::Metric
- Defined in:
- lib/archunit/metrics/calculation/metric.rb
Overview
Immutable named calculation over one extracted subject type.
Instance Attribute Summary collapse
-
#calculation ⇒ Object
readonly
Returns the value of attribute calculation.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#subject_type ⇒ Object
readonly
Returns the value of attribute subject_type.
Instance Method Summary collapse
- #calculate(subject) ⇒ Object
-
#initialize(name:, subject_type:, calculation:, description: nil) ⇒ Metric
constructor
A new instance of Metric.
Constructor Details
#initialize(name:, subject_type:, calculation:, description: nil) ⇒ Metric
Returns a new instance of Metric.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/archunit/metrics/calculation/metric.rb', line 10 def initialize(name:, subject_type:, calculation:, description: nil) name = immutable_name(name) raise ArgumentError, 'subject_type must be a Class' unless subject_type.is_a?(Class) unless calculation.respond_to?(:call) raise ArgumentError, 'calculation must respond to call' end calculation = calculation.dup.freeze description = immutable_description(description) super end |
Instance Attribute Details
#calculation ⇒ Object (readonly)
Returns the value of attribute calculation
9 10 11 |
# File 'lib/archunit/metrics/calculation/metric.rb', line 9 def calculation @calculation end |
#description ⇒ Object (readonly)
Returns the value of attribute description
9 10 11 |
# File 'lib/archunit/metrics/calculation/metric.rb', line 9 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name
9 10 11 |
# File 'lib/archunit/metrics/calculation/metric.rb', line 9 def name @name end |
#subject_type ⇒ Object (readonly)
Returns the value of attribute subject_type
9 10 11 |
# File 'lib/archunit/metrics/calculation/metric.rb', line 9 def subject_type @subject_type end |
Instance Method Details
#calculate(subject) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/archunit/metrics/calculation/metric.rb', line 22 def calculate(subject) unless subject.is_a?(subject_type) raise ArgumentError, "subject must be a #{subject_type.name.split('::').last}" end NumericValue.validate( calculation.call(subject), attribute: 'metric calculations', error_class: TypeError ) end |