Class: ArchSpec::Component

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Component

Returns a new instance of Component.



165
166
167
168
169
170
171
172
# File 'lib/archspec/model.rb', line 165

def initialize(name)
  @name = name.to_sym
  @files = Set.new
  @constants = Set.new
  @constant_occurrences = Set.new
  @file_reasons = Hash.new { |hash, key| hash[key] = Set.new }
  @constant_reasons = Hash.new { |hash, key| hash[key] = Set.new }
end

Instance Attribute Details

#constant_reasonsObject (readonly)

Returns the value of attribute constant_reasons.



163
164
165
# File 'lib/archspec/model.rb', line 163

def constant_reasons
  @constant_reasons
end

#constantsObject (readonly)

Returns the value of attribute constants.



163
164
165
# File 'lib/archspec/model.rb', line 163

def constants
  @constants
end

#file_reasonsObject (readonly)

Returns the value of attribute file_reasons.



163
164
165
# File 'lib/archspec/model.rb', line 163

def file_reasons
  @file_reasons
end

#filesObject (readonly)

Returns the value of attribute files.



163
164
165
# File 'lib/archspec/model.rb', line 163

def files
  @files
end

#nameObject (readonly)

Returns the value of attribute name.



163
164
165
# File 'lib/archspec/model.rb', line 163

def name
  @name
end

Instance Method Details

#add_constant(name, path:, reason: nil) ⇒ Object



179
180
181
182
183
# File 'lib/archspec/model.rb', line 179

def add_constant(name, path:, reason: nil)
  constants.add(name)
  @constant_occurrences.add([name, path])
  constant_reasons[name].add(reason) if reason
end

#add_file(path, reason: nil) ⇒ Object



174
175
176
177
# File 'lib/archspec/model.rb', line 174

def add_file(path, reason: nil)
  files.add(path)
  file_reasons[path].add(reason) if reason
end

#includes_constant?(name, path: nil) ⇒ Boolean

Returns:

  • (Boolean)


185
186
187
188
189
# File 'lib/archspec/model.rb', line 185

def includes_constant?(name, path: nil)
  return constants.include?(name) unless path

  @constant_occurrences.include?([name, path])
end