Class: Defmastership::Modifier::ChangeRef
- Inherits:
-
Object
- Object
- Defmastership::Modifier::ChangeRef
- Includes:
- ModifierCommon
- Defined in:
- lib/defmastership/modifier/change_ref.rb
Overview
Change references from temporary to definitive with multiple RefChangers This class smells of :reek:DataClump
Instance Attribute Summary
Attributes included from ModifierCommon
Class Method Summary collapse
-
.default_config ⇒ Hash{Symbol => Object}
The default configuration.
-
.replacement_methods ⇒ Array<Symbol>
Methods’s symbols will be called in sequence to perform the document modifications.
Instance Method Summary collapse
-
#initialize(config) ⇒ ChangeRef
constructor
A new instance of ChangeRef.
-
#replace_include_tags(_filename, line) ⇒ String
Replace the definition’s refs in tags of include statements.
-
#replace_irefs(_filename, line) ⇒ String
Replace the definition’s refs in intenal refs.
-
#replace_refdef(_filename, line) ⇒ String
Replace the definition’s ref in the line if relevant.
-
#replace_tags_in_included_files(filename, line) ⇒ String
Replace the definition’s refs in included files.
Methods included from ModifierCommon
#do_modifications, #method_missing, #respond_to_missing?, #setup_modifier_module
Constructor Details
#initialize(config) ⇒ ChangeRef
Returns a new instance of ChangeRef.
48 49 50 51 52 |
# File 'lib/defmastership/modifier/change_ref.rb', line 48 def initialize(config) @parsing_state = Core::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::ModifierCommon
Class Method Details
.default_config ⇒ Hash{Symbol => Object}
Returns the default configuration.
38 39 40 41 42 43 44 45 |
# File 'lib/defmastership/modifier/change_ref.rb', line 38 def self.default_config { def_type: '', from_regexp: '', to_template: '', next_ref: 0 } end |
.replacement_methods ⇒ Array<Symbol>
Methods’s symbols will be called in sequence to perform the document modifications
33 34 35 |
# File 'lib/defmastership/modifier/change_ref.rb', line 33 def self.replacement_methods %i[replace_refdef replace_irefs replace_include_tags replace_tags_in_included_files] end |
Instance Method Details
#replace_include_tags(_filename, line) ⇒ String
Replace the definition’s refs in tags of include statements
86 87 88 89 90 91 92 |
# File 'lib/defmastership/modifier/change_ref.rb', line 86 def (_filename, line) return line unless line.match?(Core::DMRegexp::INCLUDE) changes.reduce(line) do |res_line, (from, to)| res_line.sub(/(?<before>tags?=!?([^;]*;)?)#{from}\b/) { "#{$LAST_MATCH_INFO[:before]}#{to}" } end end |
#replace_irefs(_filename, line) ⇒ String
Replace the definition’s refs in intenal refs
73 74 75 76 77 78 79 |
# File 'lib/defmastership/modifier/change_ref.rb', line 73 def replace_irefs(_filename, 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(_filename, line) ⇒ String
Replace the definition’s ref in the line if relevant
This method smells of :reek:DataClump
60 61 62 63 64 65 66 |
# File 'lib/defmastership/modifier/change_ref.rb', line 60 def replace_refdef(_filename, line) if @parsing_state.enabled?(line) do_replace_refdef(line) else line end end |
#replace_tags_in_included_files(filename, line) ⇒ String
Replace the definition’s refs in included files
99 100 101 102 103 104 105 106 |
# File 'lib/defmastership/modifier/change_ref.rb', line 99 def (filename, line) if line.match(Core::DMRegexp::INCLUDE) Helper.( "#{Pathname(filename).dirname}/#{Helper::ParsedFilename.full_filename(Regexp.last_match)}", changes ) end line end |