Class: ArchSpec::Rules::DependencyRule

Inherits:
Object
  • Object
show all
Defined in:
lib/archspec/rules/dependency_rules.rb

Overview

Base for the allow and forbid dependency rules. Merges repeated declarations for the same source component.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, targets) ⇒ DependencyRule

Returns a new instance of DependencyRule.



15
16
17
18
# File 'lib/archspec/rules/dependency_rules.rb', line 15

def initialize(source, targets)
  @source = source.to_sym
  @targets = Array(targets).flatten.map(&:to_sym).to_set
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



13
14
15
# File 'lib/archspec/rules/dependency_rules.rb', line 13

def source
  @source
end

#targetsObject (readonly)

Returns the value of attribute targets.



13
14
15
# File 'lib/archspec/rules/dependency_rules.rb', line 13

def targets
  @targets
end

Instance Method Details

#merge!(other) ⇒ Object



24
25
26
27
# File 'lib/archspec/rules/dependency_rules.rb', line 24

def merge!(other)
  targets.merge(other.targets)
  self
end

#merge_keyObject



20
21
22
# File 'lib/archspec/rules/dependency_rules.rb', line 20

def merge_key
  [self.class, source]
end