Class: Defmastership::Modifier::UpdateDef Abstract
- Inherits:
-
Object
- Object
- Defmastership::Modifier::UpdateDef
- Includes:
- ModifierCommon
- Defined in:
- lib/defmastership/modifier/update_def.rb
Overview
Subclass and define reference_replacement to implement a
custom reference replacement class
Direct Known Subclasses
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Attributes included from ModifierCommon
Class Method Summary collapse
-
.default_config ⇒ Hash{Symbol => Object}
The default configuration.
-
.reference_regexp(reference) ⇒ Regexp
Builds a Regexp to match a particular reference defintion (with its optional version and checksum).
-
.replacement_methods ⇒ Array<Symbol>
The methods’s symbols that will be called in sequence for modifications.
Instance Method Summary collapse
-
#do_modifications(adoc_sources) ⇒ Object
Apply the modifier on all provided asciidoc sources based on modifier’s
self.replacement_methodslist. -
#initialize(config) ⇒ UpdateDef
constructor
A new instance of UpdateDef.
-
#replace_reference(_filename, line) ⇒ String
Called on each line for an opportunity for text replacement.
Methods included from ModifierCommon
#method_missing, #respond_to_missing?, #setup_modifier_module
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Defmastership::Modifier::ModifierCommon
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
15 16 17 |
# File 'lib/defmastership/modifier/update_def.rb', line 15 def document @document end |
Class Method Details
.default_config ⇒ Hash{Symbol => Object}
Returns the default configuration.
18 19 20 21 22 |
# File 'lib/defmastership/modifier/update_def.rb', line 18 def self.default_config { def_type: '' } end |
.reference_regexp(reference) ⇒ Regexp
Builds a Regexp to match a particular reference defintion (with its optional version and checksum)
34 35 36 |
# File 'lib/defmastership/modifier/update_def.rb', line 34 def self.reference_regexp(reference) Regexp.new("#{reference}#{Core::DMRegexp::DEF_VERSION_AND_CHECKSUM}") end |
.replacement_methods ⇒ Array<Symbol>
Returns the methods’s symbols that will be called in sequence for modifications.
25 26 27 |
# File 'lib/defmastership/modifier/update_def.rb', line 25 def self.replacement_methods %i[replace_reference] end |
Instance Method Details
#do_modifications(adoc_sources) ⇒ Object
Apply the modifier on all provided asciidoc sources based on modifier’s self.replacement_methods list
51 52 53 54 55 56 57 |
# File 'lib/defmastership/modifier/update_def.rb', line 51 def do_modifications(adoc_sources) adoc_sources.each_key do |adoc_file| document.parse_file_with_preprocessor(adoc_file) end super end |
#replace_reference(_filename, line) ⇒ String
Called on each line for an opportunity for text replacement
64 65 66 67 68 69 70 71 72 |
# File 'lib/defmastership/modifier/update_def.rb', line 64 def replace_reference(_filename, line) match = line.match(Core::DMRegexp::DEFINITION) return line unless match return line unless DefTypeList.new(def_type).include?(match[:type]) reference = match[:reference] line.sub(self.class.reference_regexp(reference), reference_replacement(reference, match)) end |