Class: DefMastership::RenameIncludedFilesLineModifier

Inherits:
LineModifierBase show all
Defined in:
lib/defmastership/rename_included_files_line_modifier.rb

Overview

Change included filenames on one line at a time

Instance Attribute Summary

Attributes inherited from LineModifierBase

#changes, #config

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LineModifierBase

#from_config, #method_missing, #respond_to_missing?

Constructor Details

#initializeRenameIncludedFilesLineModifier

Returns a new instance of RenameIncludedFilesLineModifier.



20
21
22
23
24
25
26
27
28
# File 'lib/defmastership/rename_included_files_line_modifier.rb', line 20

def initialize
  super
  @config = {
    from_regexp: '',
    to_template: ''
  }
  @variables = {}
  @definition_parser = DefinitionParser.new(self)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DefMastership::LineModifierBase

Class Method Details

.from_config(config) ⇒ Object



16
17
18
# File 'lib/defmastership/rename_included_files_line_modifier.rb', line 16

def self.from_config(config)
  new.from_config(config)
end

Instance Method Details

#add_line(_match, _line) ⇒ Object



49
# File 'lib/defmastership/rename_included_files_line_modifier.rb', line 49

def add_line(_match, _line) end

#add_new_definition(match, _line) ⇒ Object



45
46
47
# File 'lib/defmastership/rename_included_files_line_modifier.rb', line 45

def add_new_definition(match, _line)
  @config[:reference] = match[:reference]
end

#new_variable_def(match, line) ⇒ Object



51
52
53
54
# File 'lib/defmastership/rename_included_files_line_modifier.rb', line 51

def new_variable_def(match, line)
  @variables[match[:varname].to_sym] = match[:value]
  line
end

#replace(line) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/defmastership/rename_included_files_line_modifier.rb', line 30

def replace(line)
  match = matched?(line)

  return line unless match

  new_line =
    line.gsub(complete_regexp_from(from_regexp)) do
      text_with(match, to_template % hmerge(match))
    end

  rename_file(line, new_line)

  new_line
end