Class: Defmastership::Modifier::RenameIncludedFiles
- Inherits:
-
Object
- Object
- Defmastership::Modifier::RenameIncludedFiles
- 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
Class Method Summary collapse
-
.default_config ⇒ Hash{Symbol => Object}
The default configuration.
-
.replacement_methods ⇒ Array<Symbol>
The only replacement method symbol.
Instance Method Summary collapse
-
#initialize(config) ⇒ RenameIncludedFiles
constructor
mutant:disable.
-
#method_missing(method_name, *args) ⇒ Object
Allow to add methods from parser actions.
-
#replace(filename, line) ⇒ String
Modify line if it match.
-
#respond_to_missing?(method_name, *args) ⇒ Boolean
Allow to check if a parser action is available.
Methods included from ModifierCommon
#do_modifications, #setup_modifier_module
Constructor Details
#initialize(config) ⇒ RenameIncludedFiles
mutant:disable
55 56 57 58 59 60 61 |
# File 'lib/defmastership/modifier/rename_included_files.rb', line 55 def initialize(config) @variables = {} @definition_parser = DefinitionParser.new(self) @current_def_type = nil 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
67 68 69 70 71 72 |
# File 'lib/defmastership/modifier/rename_included_files.rb', line 67 def method_missing(method_name, *args) action = PARSER_ACTIONS[method_name] return instance_exec(*args, &action) if action super end |
Class Method Details
.default_config ⇒ Hash{Symbol => Object}
Returns the default configuration.
45 46 47 48 49 50 51 |
# File 'lib/defmastership/modifier/rename_included_files.rb', line 45 def self.default_config { def_type: '', from_regexp: '', to_template: '' } end |
.replacement_methods ⇒ Array<Symbol>
Returns the only replacement method symbol.
40 41 42 |
# File 'lib/defmastership/modifier/rename_included_files.rb', line 40 def self.replacement_methods %i[replace] end |
Instance Method Details
#replace(filename, line) ⇒ String
Modify line if it match
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/defmastership/modifier/rename_included_files.rb', line 87 def replace(filename, line) match = matched?(line) return line unless match new_line = build_new_include_line(match, line) rename_file(Pathname(filename).dirname, line, new_line) new_line end |
#respond_to_missing?(method_name, *args) ⇒ Boolean
Allow to check if a parser action is available
78 79 80 |
# File 'lib/defmastership/modifier/rename_included_files.rb', line 78 def respond_to_missing?(method_name, *args) PARSER_ACTIONS.key?(method_name) || super end |