Class: DefMastership::ChangeRefModifier
- Inherits:
-
Object
- Object
- DefMastership::ChangeRefModifier
- Includes:
- Modifier
- Defined in:
- lib/defmastership/change_ref_modifier.rb
Overview
Change references from temporary to definitive with multiple RefChangers
Defined Under Namespace
Modules: Helper
Instance Attribute Summary
Attributes included from Modifier
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(config) ⇒ ChangeRefModifier
constructor
A new instance of ChangeRefModifier.
- #replace(method, line) ⇒ Object
- #replace_irefs(line) ⇒ Object
- #replace_refdef(line) ⇒ Object
Methods included from Modifier
#apply_to_all, #apply_to_one, #do_modifications, #method_missing, #respond_to_missing?, #setup_modifier_module
Constructor Details
#initialize(config) ⇒ ChangeRefModifier
Returns a new instance of ChangeRefModifier.
37 38 39 40 41 |
# File 'lib/defmastership/change_ref_modifier.rb', line 37 def initialize(config) @parsing_state = ParsingState.new setup_modifier_module(config) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class DefMastership::Modifier
Class Method Details
.default_config ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/defmastership/change_ref_modifier.rb', line 29 def self.default_config { from_regexp: '', to_template: '', next_ref: 0 } end |
.replacement_methods ⇒ Object
25 26 27 |
# File 'lib/defmastership/change_ref_modifier.rb', line 25 def self.replacement_methods %i[replace_refdef replace_irefs] end |
Instance Method Details
#replace(method, line) ⇒ Object
43 44 45 |
# File 'lib/defmastership/change_ref_modifier.rb', line 43 def replace(method, line) public_send(:"replace_#{method}", line) end |
#replace_irefs(line) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/defmastership/change_ref_modifier.rb', line 55 def replace_irefs(line) changes.reduce(line) do |res_line, (from, to)| res_line.gsub(Helper.regexp_from(:iref, from)) do Helper.text_with(Regexp.last_match, to) end end end |
#replace_refdef(line) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/defmastership/change_ref_modifier.rb', line 47 def replace_refdef(line) if @parsing_state.enabled?(line) do_replace_refdef(line) else line end end |