Class: ArchUnit::Layers::Assertion::LayerDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/archunit/layers/assertion/layer_definition.rb

Overview

Immutable association between a layer name and its file selectors.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, filters:) ⇒ LayerDefinition

Returns a new instance of LayerDefinition.



14
15
16
17
18
# File 'lib/archunit/layers/assertion/layer_definition.rb', line 14

def initialize(name:, filters:)
  @name = layer_name(name)
  @filters = filter_values(filters)
  freeze
end

Instance Attribute Details

#filtersObject (readonly)

Returns the value of attribute filters.



12
13
14
# File 'lib/archunit/layers/assertion/layer_definition.rb', line 12

def filters
  @filters
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/archunit/layers/assertion/layer_definition.rb', line 12

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



28
29
30
# File 'lib/archunit/layers/assertion/layer_definition.rb', line 28

def ==(other)
  other.is_a?(self.class) && name == other.name && filters == other.filters
end

#hashObject



33
34
35
# File 'lib/archunit/layers/assertion/layer_definition.rb', line 33

def hash
  [self.class, name, filters].hash
end

#matches?(file_path) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/archunit/layers/assertion/layer_definition.rb', line 20

def matches?(file_path)
  Common::PatternMatching.matches_any_pattern?(file_path, filters)
end

#with_filter(filter) ⇒ Object



24
25
26
# File 'lib/archunit/layers/assertion/layer_definition.rb', line 24

def with_filter(filter)
  self.class.new(name:, filters: [*filters, filter])
end