Sha256: 44dbee8f51fded28e4b357d326e4230ea7a556fab1dc9057569c5844ec15d67b

Contents?: true

Size: 700 Bytes

Versions: 17

Compression:

Stored size: 700 Bytes

Contents

# frozen_string_literal: true

require_relative "./common"

module Fixtury
  module LocatorBackend
    class Memory

      include ::Fixtury::LocatorBackend::Common

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

      def recognized_reference?(ref)
        ref.is_a?(String) && MATCHER.match?(ref)
      end

      def recognized_value?(_val)
        true
      end

      def load_recognized_reference(ref)
        match = MATCHER.match(ref)
        return nil unless match

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

      def dump_recognized_value(value)
        "fixtury-oid-#{value.object_id}"
      end

    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
fixtury-0.4.1 lib/fixtury/locator_backend/memory.rb
fixtury-0.4.0 lib/fixtury/locator_backend/memory.rb
fixtury-0.3.5 lib/fixtury/locator_backend/memory.rb
fixtury-0.3.4 lib/fixtury/locator_backend/memory.rb
fixtury-0.3.3 lib/fixtury/locator_backend/memory.rb
fixtury-0.3.2 lib/fixtury/locator_backend/memory.rb
fixtury-0.3.1 lib/fixtury/locator_backend/memory.rb
fixtury-0.3.0 lib/fixtury/locator_backend/memory.rb
fixtury-0.3.0.beta lib/fixtury/locator_backend/memory.rb
fixtury-0.2.1 lib/fixtury/locator_backend/memory.rb
fixtury-0.2.0 lib/fixtury/locator_backend/memory.rb
fixtury-0.1.0 lib/fixtury/locator_backend/memory.rb
fixtury-0.1.0.rc1 lib/fixtury/locator_backend/memory.rb
fixtury-0.1.0.beta2 lib/fixtury/locator_backend/memory.rb
fixtury-0.1.0.beta lib/fixtury/locator_backend/memory.rb
fixtury-0.1.0.alpha2 lib/fixtury/locator_backend/memory.rb
fixtury-0.1.0.alpha lib/fixtury/locator_backend/memory.rb