Module: Defmastership::Modifier::ModifierCommon Abstract
- Included in:
- ChangeRef, RenameIncludedFiles, UpdateDef
- Defined in:
- lib/defmastership/modifier/modifier_common.rb
Overview
Include and define self.replacement_methods and self.default_config
Defines common methods and attributes for line modifiers
Instance Attribute Summary collapse
-
#changes ⇒ Array<Array<String>>
readonly
Provides the list of performed modifications (each line: [Modifier, Was, Becomes]).
-
#config ⇒ YAML
readonly
Stores the configuration of this modifier.
Instance Method Summary collapse
-
#do_modifications(adoc_sources) ⇒ Object
Apply the modifier on all provided asciidoc sources based on modifier’s
replacement_methodslist. -
#method_missing(method_name, *args) ⇒ Object
Allow to view config items as methods.
-
#respond_to_missing?(method_name, *args) ⇒ Boolean
Allow to check if a config item is available.
-
#setup_modifier_module(config) ⇒ Object
Setup config from class’s default config and provided config.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
Allow to view config items as methods
30 31 32 33 34 35 |
# File 'lib/defmastership/modifier/modifier_common.rb', line 30 def method_missing(method_name, *args) config_method_name = config[method_name] return config_method_name if config_method_name super end |
Instance Attribute Details
#changes ⇒ Array<Array<String>> (readonly)
Provides the list of performed modifications (each line: [Modifier, Was, Becomes])
16 17 18 |
# File 'lib/defmastership/modifier/modifier_common.rb', line 16 def changes @changes end |
#config ⇒ YAML (readonly)
Stores the configuration of this modifier
12 13 14 |
# File 'lib/defmastership/modifier/modifier_common.rb', line 12 def config @config end |
Instance Method Details
#do_modifications(adoc_sources) ⇒ Object
Apply the modifier on all provided asciidoc sources based on modifier’s replacement_methods list
51 52 53 54 55 |
# File 'lib/defmastership/modifier/modifier_common.rb', line 51 def do_modifications(adoc_sources) self.class.replacement_methods.reduce(adoc_sources) do |texts, method| apply_to_all(texts, method) end end |
#respond_to_missing?(method_name, *args) ⇒ Boolean
Allow to check if a config item is available
41 42 43 |
# File 'lib/defmastership/modifier/modifier_common.rb', line 41 def respond_to_missing?(method_name, *args) config.key?(method_name) || super end |
#setup_modifier_module(config) ⇒ Object
Setup config from class’s default config and provided config
21 22 23 24 |
# File 'lib/defmastership/modifier/modifier_common.rb', line 21 def setup_modifier_module(config) @config = self.class.default_config.merge(config) @changes = [] end |