Sha256: d80fce2d5c08688fe20ed80085e2401c9e777a48de0302db3541487bcb0b4f83

Contents?: true

Size: 850 Bytes

Versions: 9

Compression:

Stored size: 850 Bytes

Contents

# frozen_string_literal: true

require_relative "./common"

module Fixtury
  module LocatorBackend
    class Memory

      include ::Fixtury::LocatorBackend::Common

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

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

      def recognizable_value?(_stored_value)
        true
      end

      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

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

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
fixtury-2.0.0 lib/fixtury/locator_backend/memory.rb
fixtury-1.0.1 lib/fixtury/locator_backend/memory.rb
fixtury-1.0.0 lib/fixtury/locator_backend/memory.rb
fixtury-1.0.0.beta7 lib/fixtury/locator_backend/memory.rb
fixtury-1.0.0.beta6 lib/fixtury/locator_backend/memory.rb
fixtury-1.0.0.beta5 lib/fixtury/locator_backend/memory.rb
fixtury-1.0.0.beta4 lib/fixtury/locator_backend/memory.rb
fixtury-1.0.0.beta3 lib/fixtury/locator_backend/memory.rb
fixtury-1.0.0.beta2 lib/fixtury/locator_backend/memory.rb