Module: DefMastership::Modifier

Included in:
ChangeRefModifier, RenameIncludedFilesModifier, UpdateDefModifier
Defined in:
lib/defmastership/modifier.rb

Overview

define methods 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



14
15
16
17
18
19
# File 'lib/defmastership/modifier.rb', line 14

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

#changesObject (readonly)

Returns the value of attribute changes.



7
8
9
# File 'lib/defmastership/modifier.rb', line 7

def changes
  @changes
end

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/defmastership/modifier.rb', line 7

def config
  @config
end

Instance Method Details

#apply_to_all(texts, method) ⇒ Object



25
26
27
28
29
# File 'lib/defmastership/modifier.rb', line 25

def apply_to_all(texts, method)
  texts.transform_values do |text|
    apply_to_one(text, method)
  end
end

#apply_to_one(text, method) ⇒ Object



31
32
33
34
# File 'lib/defmastership/modifier.rb', line 31

def apply_to_one(text, method)
  text.lines.map { |line| public_send(method, line) }
      .join
end

#do_modifications(adoc_sources) ⇒ Object



36
37
38
39
40
# File 'lib/defmastership/modifier.rb', line 36

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

Returns:

  • (Boolean)


21
22
23
# File 'lib/defmastership/modifier.rb', line 21

def respond_to_missing?(method_name, *args)
  config.key?(method_name) || super
end

#setup_modifier_module(config) ⇒ Object



9
10
11
12
# File 'lib/defmastership/modifier.rb', line 9

def setup_modifier_module(config)
  @config = self.class.default_config.merge(config)
  @changes = []
end