Class: ActiveCypher::Fixtures::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/active_cypher/fixtures/registry.rb

Overview

Singleton registry for logical ref => model instance mapping

Class Method Summary collapse

Class Method Details

.[](ref) ⇒ Object

Allow bracket access: Registry



32
33
34
# File 'lib/active_cypher/fixtures/registry.rb', line 32

def [](ref)
  get(ref)
end

.add(ref, obj) ⇒ Object

Store loaded instance

Parameters:

  • ref (Symbol, String)
  • obj (Object)

Raises:

  • (ArgumentError)


13
14
15
16
17
# File 'lib/active_cypher/fixtures/registry.rb', line 13

def add(ref, obj)
  raise ArgumentError, "Duplicate fixture ref: #{ref.inspect}" if @store.key?(ref.to_sym)

  @store[ref.to_sym] = obj
end

.allObject

For debugging or introspection



37
38
39
# File 'lib/active_cypher/fixtures/registry.rb', line 37

def all
  @store.dup
end

.get(ref) ⇒ Object?

Fetch in tests (‘[]` delegate)

Parameters:

  • ref (Symbol, String)

Returns:

  • (Object, nil)


22
23
24
# File 'lib/active_cypher/fixtures/registry.rb', line 22

def get(ref)
  @store[ref.to_sym]
end

.reset!Object

Purge registry between loads



27
28
29
# File 'lib/active_cypher/fixtures/registry.rb', line 27

def reset!
  @store.clear
end