Sha256: 16df91e8ffa5edeb4ce52079804a06ce544b931981a6f44df559caab26f482cf

Contents?: true

Size: 927 Bytes

Versions: 13

Compression:

Stored size: 927 Bytes

Contents

# frozen_string_literal: true

module Fixtury
  class Locator

    class << self

      attr_accessor :instance

      def instance
        @instance ||= begin
          require "fixtury/locator_backend/memory"
          ::Fixtury::Locator.new(
            backend: ::Fixtury::LocatorBackend::Memory.new
          )
        end
      end

    end

    attr_reader :backend

    def initialize(backend:)
      @backend = backend
    end

    def recognize?(ref)
      raise ArgumentError, "Unable to recognize a nil ref" if ref.nil?

      backend.recognized_reference?(ref)
    end

    def load(ref)
      raise ArgumentError, "Unable to load a nil ref" if ref.nil?

      backend.load(ref)
    end

    def dump(value)
      raise ArgumentError, "Unable to dump a nil value" if value.nil?

      ref = backend.dump(value)
      raise ArgumentError, "The value resulted in a nil ref" if ref.nil?

      ref
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
fixtury-0.4.1 lib/fixtury/locator.rb
fixtury-0.4.0 lib/fixtury/locator.rb
fixtury-0.3.5 lib/fixtury/locator.rb
fixtury-0.3.4 lib/fixtury/locator.rb
fixtury-0.3.3 lib/fixtury/locator.rb
fixtury-0.3.2 lib/fixtury/locator.rb
fixtury-0.3.1 lib/fixtury/locator.rb
fixtury-0.3.0 lib/fixtury/locator.rb
fixtury-0.3.0.beta lib/fixtury/locator.rb
fixtury-0.2.1 lib/fixtury/locator.rb
fixtury-0.2.0 lib/fixtury/locator.rb
fixtury-0.1.0 lib/fixtury/locator.rb
fixtury-0.1.0.rc1 lib/fixtury/locator.rb