Class: ArchUnit::Metrics::FluentApi::MetricsBuilder

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

Overview

Immutable scope builder for numeric metrics over Ruby source.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_locator: nil, filters: []) ⇒ MetricsBuilder

Returns a new instance of MetricsBuilder.



20
21
22
23
24
# File 'lib/archunit/metrics/fluentapi/metrics_builder.rb', line 20

def initialize(project_locator: nil, filters: [])
  @project_locator = immutable_project_locator(project_locator)
  @filters = immutable_filters(filters)
  freeze
end

Instance Attribute Details

#filtersObject (readonly)

Returns the value of attribute filters.



18
19
20
# File 'lib/archunit/metrics/fluentapi/metrics_builder.rb', line 18

def filters
  @filters
end

#project_locatorObject (readonly)

Returns the value of attribute project_locator.



18
19
20
# File 'lib/archunit/metrics/fluentapi/metrics_builder.rb', line 18

def project_locator
  @project_locator
end

Instance Method Details

#analyzeObject



58
59
60
61
62
# File 'lib/archunit/metrics/fluentapi/metrics_builder.rb', line 58

def analyze
  project = Extraction.extract_project_info(project_locator)
  selected_files = project.files.filter_map { |file| selected_file_info(file) }
  Extraction::ProjectInfo.new(project_root: project.project_root, files: selected_files)
end

#countObject



42
43
44
# File 'lib/archunit/metrics/fluentapi/metrics_builder.rb', line 42

def count
  CountMetricsBuilder.new(self)
end

#custom_metric(name, description, calculation) ⇒ Object



54
55
56
# File 'lib/archunit/metrics/fluentapi/metrics_builder.rb', line 54

def custom_metric(name, description, calculation)
  CustomMetricBuilder.new(scope: self, name:, description:, calculation:)
end

#distanceObject



50
51
52
# File 'lib/archunit/metrics/fluentapi/metrics_builder.rb', line 50

def distance
  DistanceMetricsBuilder.new(self)
end

#for_classes_matching(pattern, except: nil) ⇒ Object



38
39
40
# File 'lib/archunit/metrics/fluentapi/metrics_builder.rb', line 38

def for_classes_matching(pattern, except: nil)
  with_filter(Common::RegexFactory.classname_matcher(pattern, except:))
end

#in_folder(pattern, except: nil) ⇒ Object



30
31
32
# File 'lib/archunit/metrics/fluentapi/metrics_builder.rb', line 30

def in_folder(pattern, except: nil)
  with_filter(Common::RegexFactory.folder_matcher(pattern, except:))
end

#in_path(pattern, except: nil) ⇒ Object



34
35
36
# File 'lib/archunit/metrics/fluentapi/metrics_builder.rb', line 34

def in_path(pattern, except: nil)
  with_filter(Common::RegexFactory.path_matcher(pattern, except:))
end

#lcomObject



46
47
48
# File 'lib/archunit/metrics/fluentapi/metrics_builder.rb', line 46

def lcom
  LCOMMetricsBuilder.new(self)
end

#with_name(pattern, except: nil) ⇒ Object



26
27
28
# File 'lib/archunit/metrics/fluentapi/metrics_builder.rb', line 26

def with_name(pattern, except: nil)
  with_filter(Common::RegexFactory.filename_matcher(pattern, except:))
end