Class: LabelWeaver::Merger

Inherits:
Object
  • Object
show all
Defined in:
lib/label_weaver/merger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_root_dir:, repo:, configuration: nil, logger: nil) ⇒ Merger

Returns a new instance of Merger.



9
10
11
12
13
14
# File 'lib/label_weaver/merger.rb', line 9

def initialize(project_root_dir:, repo:, configuration: nil, logger: nil)
  @configuration = configuration
  @logger = logger
  @project_root_dir = project_root_dir
  @repo = repo
end

Instance Attribute Details

#project_root_dirObject (readonly)

Returns the value of attribute project_root_dir.



7
8
9
# File 'lib/label_weaver/merger.rb', line 7

def project_root_dir
  @project_root_dir
end

#repoObject (readonly)

Returns the value of attribute repo.



7
8
9
# File 'lib/label_weaver/merger.rb', line 7

def repo
  @repo
end

Instance Method Details

#merge!Object



20
21
22
23
24
25
26
27
# File 'lib/label_weaver/merger.rb', line 20

def merge!
  merge_entries.each do |entry|
    entry => {source_file:, target_file:, overrides_file:}
    logger.debug "Merging '#{overrides_file}' and '#{source_file}' into '#{target_file}'..."

    merge_file(project_root_dir + source_file, project_root_dir + target_file, project_root_dir + overrides_file)
  end
end

#present?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/label_weaver/merger.rb', line 16

def present?
  merge_entries.any?
end

#restore!Object



29
30
31
32
33
34
35
# File 'lib/label_weaver/merger.rb', line 29

def restore!
  merge_entries.each do |entry|
    logger.debug "Restoring '#{entry[:target_file]}'..."

    restore_file(entry[:target_file])
  end
end