Class: LockJar::Domain::DslMerger

Inherits:
Object
  • Object
show all
Defined in:
lib/lock_jar/domain/dsl_merger.rb

Overview

Merge DSLs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(into_dsl, from_dsl, into_groups = nil) ⇒ DslMerger

Returns a new instance of DslMerger.

Parameters:

  • into_dsl (LockJar::Domain::Dsl)

    dsl that is merged into

  • from_dsl (LockJar::Domain::Dsl)

    dsl that is merged from

  • into_group (String)

    force only runtime and default groups to be loaded into this group


26
27
28
29
30
# File 'lib/lock_jar/domain/dsl_merger.rb', line 26

def initialize(into_dsl, from_dsl, into_groups = nil)
  @into_dsl = into_dsl
  @from_dsl = from_dsl
  @into_groups = into_groups
end

Instance Attribute Details

#from_dslObject (readonly)

Returns the value of attribute from_dsl


20
21
22
# File 'lib/lock_jar/domain/dsl_merger.rb', line 20

def from_dsl
  @from_dsl
end

#into_dslObject (readonly)

Returns the value of attribute into_dsl


20
21
22
# File 'lib/lock_jar/domain/dsl_merger.rb', line 20

def into_dsl
  @into_dsl
end

#into_groupsObject (readonly)

Returns the value of attribute into_groups


20
21
22
# File 'lib/lock_jar/domain/dsl_merger.rb', line 20

def into_groups
  @into_groups
end

Instance Method Details

#mergeLockJar::Domain::Dsl

Merge LockJar::Domain::Dsl


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/lock_jar/domain/dsl_merger.rb', line 34

def merge
  merged_dsl = into_dsl.dup

  merged_dsl.remote_repositories = remote_repositories

  merged_dsl.artifacts = artifact_groups(into_groups)

  from_dsl.maps.each do |artifact, paths|
    maps = into_dsl.maps[artifact] || []
    merged_dsl.maps[artifact] = (maps + paths).uniq
  end

  from_dsl.excludes.each do |exclude|
    merged_dsl.excludes << exclude unless into_dsl.excludes.include? exclude
  end

  merged_dsl.merged << from_dsl.file_path if from_dsl.file_path

  merged_dsl
end