Module: Fixtury::LocatorBackend::Common

Included in:
GlobalId, Memory
Defined in:
lib/fixtury/locator_backend/common.rb

Instance Method Summary collapse

Instance Method Details

#dump(stored_value) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fixtury/locator_backend/common.rb', line 38

def dump(stored_value)
  return dump_value(stored_value) if recognizable_value?(stored_value)

  case stored_value
  when Array
    stored_value.map { |subvalue| dump(subvalue) }
  when Hash
    stored_value.each_with_object({}) do |(k, subvalue), h|
      h[k] = dump(subvalue)
    end
  else
    raise Errors::UnrecognizableLocatorError.new(:dump, stored_value)
  end
end

#dump_value(_stored_value) ⇒ Object

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/fixtury/locator_backend/common.rb', line 19

def dump_value(_stored_value)
  raise NotImplementedError
end

#load(locator_value) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fixtury/locator_backend/common.rb', line 23

def load(locator_value)
  return load_reference(locator_value) if recognizable_key?(locator_value)

  case locator_value
  when Array
    locator_value.map { |subvalue| self.load(subvalue) }
  when Hash
    locator_value.each_with_object({}) do |(k, subvalue), h|
      h[k] = self.load(subvalue)
    end
  else
    raise Errors::UnrecognizableLocatorError.new(:load, locator_value)
  end
end

#load_reference(_locator_value) ⇒ Object

Raises:

  • (NotImplementedError)


15
16
17
# File 'lib/fixtury/locator_backend/common.rb', line 15

def load_reference(_locator_value)
  raise NotImplementedError
end

#recognizable_key?(_locator_value) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


7
8
9
# File 'lib/fixtury/locator_backend/common.rb', line 7

def recognizable_key?(_locator_value)
  raise NotImplementedError
end

#recognizable_value?(_stored_value) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


11
12
13
# File 'lib/fixtury/locator_backend/common.rb', line 11

def recognizable_value?(_stored_value)
  raise NotImplementedError
end