Class: Fixtury::LocatorBackend::GlobalId

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

Constant Summary collapse

MATCHER =
%r{^gid://}.freeze

Instance Method Summary collapse

Methods included from Common

#dump, #load

Instance Method Details

#dump_value(stored_value) ⇒ Object



26
27
28
# File 'lib/fixtury/locator_backend/global_id.rb', line 26

def dump_value(stored_value)
  stored_value.to_global_id.to_s
end

#load_reference(locator_value) ⇒ Object



22
23
24
# File 'lib/fixtury/locator_backend/global_id.rb', line 22

def load_reference(locator_value)
  ::GlobalID::Locator.locate locator_value
end

#recognizable_key?(locator_value) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/fixtury/locator_backend/global_id.rb', line 14

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

#recognizable_value?(stored_value) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/fixtury/locator_backend/global_id.rb', line 18

def recognizable_value?(stored_value)
  stored_value.respond_to?(:to_global_id)
end