Class: Fixtury::LocatorBackend::Memory

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/fixtury/locator_backend/memory.rb

Constant Summary collapse

MATCHER =
/^fixtury-oid-(?<process_id>[\d]+)-(?<object_id>[\d]+)$/.freeze

Instance Method Summary collapse

Methods included from Common

#dump, #load

Instance Method Details

#dump_value(stored_value) ⇒ Object



31
32
33
# File 'lib/fixtury/locator_backend/memory.rb', line 31

def dump_value(stored_value)
  "fixtury-oid-#{Process.pid}-#{stored_value.object_id}"
end

#load_reference(locator_value) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/fixtury/locator_backend/memory.rb', line 21

def load_reference(locator_value)
  match = MATCHER.match(locator_value)
  return nil unless match
  return nil unless match[:process_id].to_i == Process.pid

  ::ObjectSpace._id2ref(match[:object_id].to_i)
rescue RangeError
  nil
end

#recognizable_key?(locator_value) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/fixtury/locator_backend/memory.rb', line 13

def recognizable_key?(locator_value)
  locator_value.is_a?(String) && MATCHER.match?(locator_value)
end

#recognizable_value?(_stored_value) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/fixtury/locator_backend/memory.rb', line 17

def recognizable_value?(_stored_value)
  true
end