Class: LayerChecker::Violation

Inherits:
Object
  • Object
show all
Defined in:
lib/layer_checker/violation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_file:, source_module:, target_constant:, target_module:, line_number: nil, violation_type: :dependency) ⇒ Violation

Returns a new instance of Violation.



8
9
10
11
12
13
14
15
16
# File 'lib/layer_checker/violation.rb', line 8

def initialize(source_file:, source_module:, target_constant:, 
               target_module:, line_number: nil, violation_type: :dependency)
  @source_file = source_file
  @source_module = source_module
  @target_constant = target_constant
  @target_module = target_module
  @line_number = line_number
  @violation_type = violation_type
end

Instance Attribute Details

#line_numberObject (readonly)

Returns the value of attribute line_number.



5
6
7
# File 'lib/layer_checker/violation.rb', line 5

def line_number
  @line_number
end

#source_fileObject (readonly)

Returns the value of attribute source_file.



5
6
7
# File 'lib/layer_checker/violation.rb', line 5

def source_file
  @source_file
end

#source_moduleObject (readonly)

Returns the value of attribute source_module.



5
6
7
# File 'lib/layer_checker/violation.rb', line 5

def source_module
  @source_module
end

#target_constantObject (readonly)

Returns the value of attribute target_constant.



5
6
7
# File 'lib/layer_checker/violation.rb', line 5

def target_constant
  @target_constant
end

#target_moduleObject (readonly)

Returns the value of attribute target_module.



5
6
7
# File 'lib/layer_checker/violation.rb', line 5

def target_module
  @target_module
end

#violation_typeObject (readonly)

Returns the value of attribute violation_type.



5
6
7
# File 'lib/layer_checker/violation.rb', line 5

def violation_type
  @violation_type
end

Instance Method Details

#to_hObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/layer_checker/violation.rb', line 23

def to_h
  {
    source_file: @source_file,
    source_module: @source_module&.to_s,
    target_constant: @target_constant,
    target_module: @target_module&.to_s,
    line_number: @line_number,
    violation_type: @violation_type
  }
end

#to_sObject



18
19
20
21
# File 'lib/layer_checker/violation.rb', line 18

def to_s
  location = @line_number ? "#{@source_file}:#{@line_number}" : @source_file
  "#{location}: #{@source_module} cannot depend on #{@target_module} (#{@target_constant})"
end