Class: ViewSpec::Registry

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/view_spec/registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



7
8
9
10
# File 'lib/view_spec/registry.rb', line 7

def initialize
  @specs = SpecCollection.new
  @source_files = {}
end

Instance Attribute Details

#specsObject (readonly)

Returns the value of attribute specs.



4
5
6
# File 'lib/view_spec/registry.rb', line 4

def specs
  @specs
end

Instance Method Details

#add(source_path, subject, &block) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/view_spec/registry.rb', line 12

def add(source_path, subject, &block)
  delete(subject)

  source_file = source_file(source_path)
  @specs << Spec.new(source_file, subject, &block)
  @specs.last
end

#clear!Object



29
30
31
32
33
34
35
36
# File 'lib/view_spec/registry.rb', line 29

def clear!
  @source_files.each do |key, file|
    MethodSource.instance_variable_get(:@lines_for_file)&.delete(file.absolute_path.to_s)
  end

  @specs.clear
  @source_files.clear
end

#delete(subject) ⇒ Object



24
25
26
27
# File 'lib/view_spec/registry.rb', line 24

def delete(subject)
  index = @specs.index { _1.subject == subject }
  @specs.delete_at(index) unless index.nil?
end

#source_file(path) ⇒ Object



20
21
22
# File 'lib/view_spec/registry.rb', line 20

def source_file(path)
  @source_files[path.to_s] ||= SourceFile.new(path)
end