Class: DefMastership::RenameIncludedFilesModifier

Inherits:
Object
  • Object
show all
Includes:
Modifier
Defined in:
lib/defmastership/rename_included_files_modifier.rb

Overview

Change included filenames on one line at a time

Defined Under Namespace

Modules: Helper

Instance Attribute Summary

Attributes included from Modifier

#changes, #config

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Modifier

#apply_to_all, #apply_to_one, #do_modifications, #setup_modifier_module

Constructor Details

#initialize(config) ⇒ RenameIncludedFilesModifier

Returns a new instance of RenameIncludedFilesModifier.



46
47
48
49
50
51
# File 'lib/defmastership/rename_included_files_modifier.rb', line 46

def initialize(config)
  @variables = {}
  @definition_parser = DefinitionParser.new(self)

  setup_modifier_module(config)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



53
54
55
56
57
58
# File 'lib/defmastership/rename_included_files_modifier.rb', line 53

def method_missing(method_name, *args)
  action = PARSER_ACTIONS[method_name]
  return instance_exec(*args, &action) if action

  super
end

Class Method Details

.default_configObject



39
40
41
42
43
44
# File 'lib/defmastership/rename_included_files_modifier.rb', line 39

def self.default_config
  {
    from_regexp: '',
    to_template: ''
  }
end

.replacement_methodsObject



35
36
37
# File 'lib/defmastership/rename_included_files_modifier.rb', line 35

def self.replacement_methods
  %i[replace]
end

Instance Method Details

#replace(line) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/defmastership/rename_included_files_modifier.rb', line 64

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

  return line unless match

  new_line = build_new_include_line(match, line)

  rename_file(line, new_line)

  new_line
end

#respond_to_missing?(method_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/defmastership/rename_included_files_modifier.rb', line 60

def respond_to_missing?(method_name, *args)
  PARSER_ACTIONS.key?(method_name) || super
end