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

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



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

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



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

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



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

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



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

def self.replacement_methods
  i[replace]
end

Instance Method Details

#replace(line) ⇒ String

Modify line if it match

Returns:

  • (String)

    the modified line



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

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)


70
71
72
# File 'lib/defmastership/modifier/rename_included_files.rb', line 70

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