Class: DefMastership::ChangeRefModifier

Inherits:
Object
  • Object
show all
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

#changes, #config

Class Method Summary collapse

Instance Method Summary collapse

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_configObject



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_methodsObject



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