Class: ArchSpec::ComponentSpec
- Inherits:
-
Object
- Object
- ArchSpec::ComponentSpec
- Defined in:
- lib/archspec/component_spec.rb
Instance Attribute Summary collapse
-
#constants ⇒ Object
readonly
Returns the value of attribute constants.
-
#file_patterns ⇒ Object
readonly
Returns the value of attribute file_patterns.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespaces ⇒ Object
readonly
Returns the value of attribute namespaces.
Instance Method Summary collapse
-
#initialize(name, files: [], namespace: nil, constants: nil) ⇒ ComponentSpec
constructor
A new instance of ComponentSpec.
- #matches_constant?(name) ⇒ Boolean
- #merge!(other) ⇒ Object
Constructor Details
#initialize(name, files: [], namespace: nil, constants: nil) ⇒ ComponentSpec
Returns a new instance of ComponentSpec.
7 8 9 10 11 12 |
# File 'lib/archspec/component_spec.rb', line 7 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
#constants ⇒ Object (readonly)
Returns the value of attribute constants.
5 6 7 |
# File 'lib/archspec/component_spec.rb', line 5 def constants @constants end |
#file_patterns ⇒ Object (readonly)
Returns the value of attribute file_patterns.
5 6 7 |
# File 'lib/archspec/component_spec.rb', line 5 def file_patterns @file_patterns end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/archspec/component_spec.rb', line 5 def name @name end |
#namespaces ⇒ Object (readonly)
Returns the value of attribute namespaces.
5 6 7 |
# File 'lib/archspec/component_spec.rb', line 5 def namespaces @namespaces end |
Instance Method Details
#matches_constant?(name) ⇒ Boolean
21 22 23 24 25 26 27 28 |
# File 'lib/archspec/component_spec.rb', line 21 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
14 15 16 17 18 19 |
# File 'lib/archspec/component_spec.rb', line 14 def merge!(other) @file_patterns |= other.file_patterns @namespaces |= other.namespaces @constants |= other.constants self end |