Class: ArchSpec::ComponentSpec

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, files: [], namespace: nil, constants: nil) ⇒ ComponentSpec

Returns a new instance of ComponentSpec.



5
6
7
8
9
10
# File 'lib/archspec/component_spec.rb', line 5

def initialize(name, files: [], namespace: nil, constants: nil)
  @name = name.to_sym
  @file_patterns = Array(files).compact.map(&:to_s)
  @namespaces = Array(namespace).compact.map { |value| normalize_constant(value) }
  @constants = Array(constants).compact.map { |value| normalize_constant(value) }
end

Instance Attribute Details

#constantsObject (readonly)

Returns the value of attribute constants.



3
4
5
# File 'lib/archspec/component_spec.rb', line 3

def constants
  @constants
end

#file_patternsObject (readonly)

Returns the value of attribute file_patterns.



3
4
5
# File 'lib/archspec/component_spec.rb', line 3

def file_patterns
  @file_patterns
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/archspec/component_spec.rb', line 3

def name
  @name
end

#namespacesObject (readonly)

Returns the value of attribute namespaces.



3
4
5
# File 'lib/archspec/component_spec.rb', line 3

def namespaces
  @namespaces
end

Instance Method Details

#matches_constant?(name) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
# File 'lib/archspec/component_spec.rb', line 19

def matches_constant?(name)
  normalized = normalize_constant(name)

  constants.include?(normalized) ||
    namespaces.any? do |namespace|
      normalized == namespace || normalized.start_with?("#{namespace}::")
    end
end

#merge!(other) ⇒ Object



12
13
14
15
16
17
# File 'lib/archspec/component_spec.rb', line 12

def merge!(other)
  @file_patterns |= other.file_patterns
  @namespaces |= other.namespaces
  @constants |= other.constants
  self
end