Module: Defmastership::Modifier::ModifierCommon Abstract

Included in:
ChangeRef, RenameIncludedFiles, UpdateDef
Defined in:
lib/defmastership/modifier/modifier_common.rb

Overview

This module is abstract.

Include and define self.replacement_methods and self.default_config

Defines common methods and attributes for line modifiers

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • method_name (Symbol)

    the name of the method

  • args (Array<Object>)

    the arguments of the method



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

#changesArray<Array<String>> (readonly)

Provides the list of performed modifications (each line: [Modifier, Was, Becomes])

Returns:

  • (Array<Array<String>>)

    List of performed modifications



16
17
18
# File 'lib/defmastership/modifier/modifier_common.rb', line 16

def changes
  @changes
end

#configYAML (readonly)

Stores the configuration of this modifier

Returns:

  • (YAML)

    configuration as eventualy modified



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

Parameters:

  • adoc_sources (Hash{String => String})

    asciidoc sources

    • :key filename

    • :value file content



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

Parameters:

  • method_name (Symbol)

    the name of the method

  • args (Array<Object>)

    the arguments of the method

Returns:

  • (Boolean)


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

Parameters:

  • config (YAML)

    the modifier’s provided configurations



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