Class: RubyLsp::FactoryBot::FactoryIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_lsp/factory_bot/factory_index.rb

Defined Under Namespace

Classes: Entry

Instance Method Summary collapse

Constructor Details

#initializeFactoryIndex

Returns a new instance of FactoryIndex.



11
12
13
14
# File 'lib/ruby_lsp/factory_bot/factory_index.rb', line 11

def initialize
  @mutex = Mutex.new
  @entries = {}
end

Instance Method Details

#lookup(name) ⇒ Object



27
28
29
# File 'lib/ruby_lsp/factory_bot/factory_index.rb', line 27

def lookup(name)
  @mutex.synchronize { @entries[name.to_s] }
end

#rebuild!(workspace_root) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby_lsp/factory_bot/factory_index.rb', line 16

def rebuild!(workspace_root)
  new_entries = {}
  factory_pattern = File.join(workspace_root, 'spec', 'factories', '**', '*.rb')

  Dir.glob(factory_pattern).each do |path|
    parse_factory_file(path, new_entries)
  end

  @mutex.synchronize { @entries = new_entries }
end