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
Defined Under Namespace
Modules: Helper
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
A new instance of RenameIncludedFiles.
-
#method_missing(method_name, *args) ⇒ Object
Allow to add methods from parser actions.
-
#replace(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
Returns a new instance of RenameIncludedFiles.
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
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_config ⇒ Hash{Symbol => Object}
Returns 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_methods ⇒ Array<Symbol>
Returns 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
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
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 |