Class: Defmastership::Modifier::RenameIncludedFiles

Inherits:
Object
  • Object
show all
Includes:
ModifierCommon
Defined in:
lib/defmastership/modifier/rename_included_files.rb

Overview

Change included filenames on one line at a time

Defined Under Namespace

Modules: Helper

Instance Attribute Summary

Attributes included from ModifierCommon

#changes, #config

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModifierCommon

#do_modifications, #setup_modifier_module

Constructor Details

#initialize(config) ⇒ RenameIncludedFiles

Returns a new instance of RenameIncludedFiles.

Parameters:

  • config (YAML)

    the modifier’s provided configurations



50
51
52
53
54
55
# File 'lib/defmastership/modifier/rename_included_files.rb', line 50

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

Allow to add methods from parser actions

Parameters:

  • method_name (Symbol)

    the name of the method

  • args (Array<Object>)

    the arguments of the method



61
62
63
64
65
66
# File 'lib/defmastership/modifier/rename_included_files.rb', line 61

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

  super
end

Class Method Details

.default_configHash{Symbol => Object}

Returns the default configuration.

Returns:

  • (Hash{Symbol => Object})

    the default configuration



42
43
44
45
46
47
# File 'lib/defmastership/modifier/rename_included_files.rb', line 42

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

.replacement_methodsArray<Symbol>

Returns the only replacement method symbol.

Returns:

  • (Array<Symbol>)

    the only replacement method symbol



37
38
39
# File 'lib/defmastership/modifier/rename_included_files.rb', line 37

def self.replacement_methods
  %i[replace]
end

Instance Method Details

#replace(line) ⇒ String

Modify line if it match

Returns:

  • (String)

    the modified line



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/defmastership/modifier/rename_included_files.rb', line 79

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

Allow to check if a parser action is available

Parameters:

  • method_name (Symbol)

    the name of the method

  • args (Array<Object>)

    the arguments of the method

Returns:

  • (Boolean)


72
73
74
# File 'lib/defmastership/modifier/rename_included_files.rb', line 72

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