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
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.
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
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_config ⇒ Hash{Symbol => Object}
Returns 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_methods ⇒ Array<Symbol>
Returns 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
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
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 |