Class: BulletmarkRepairer::CorrectorBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/bulletmark_repairer/corrector_builder.rb

Constant Summary collapse

ASSOCIATIONS =
'__EMBEDDED_ASSOCIATIONS__'
LINE_NO =
'__EMBEDDED_LINE_NO__'
ACTION =
'__EMBEDDED_ACTION__'
INSTANCE_VARIABLE_NAME =
'__EMBEDDED_INSTANCE_VARIABLE_NAME__'

Instance Method Summary collapse

Constructor Details

#initialize(dir:, marker:, associations:) ⇒ CorrectorBuilder

Returns a new instance of CorrectorBuilder.



10
11
12
13
14
15
16
# File 'lib/bulletmark_repairer/corrector_builder.rb', line 10

def initialize(dir:, marker:, associations:)
  @dir = dir
  @marker = marker
  @associations = associations
  @action = marker.action
  @instance_variable_name = marker.instance_variable_name
end

Instance Method Details

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bulletmark_repairer/corrector_builder.rb', line 18

def execute
  if @marker.retry
    corrector_name = '/retry_corrector.rb'
    File.open("#{@dir}#{corrector_name}", 'w') do |f|
      corrector = Pathname.new(__FILE__).sub('/corrector_builder.rb', corrector_name)
      src = File.read(corrector)
      src
        .sub!(ASSOCIATIONS, @associations[:base].to_s)
        .sub!(LINE_NO, @marker.line_no)
      f.puts src
      f
    end.path
  else
    corrector_name = '/controller_corrector.rb'
    File.open("#{@dir}#{corrector_name}", 'w') do |f|
      corrector = Pathname.new(__FILE__).sub('/corrector_builder.rb', corrector_name)
      src = File.read(corrector)
      src
        .sub!(ASSOCIATIONS, @associations[:base].to_s)
        .sub!(ACTION, @action)
        .sub!(INSTANCE_VARIABLE_NAME, @instance_variable_name)
      f.puts src
      f
    end.path
  end
end