Sha256: 0815f90cbc9e4b03b147f25066f269aa421e5a4e7dd4bc43143f6b3aaee6460a

Contents?: true

Size: 947 Bytes

Versions: 3

Compression:

Stored size: 947 Bytes

Contents

# frozen_string_literal: true

module Fixtury
  # Acts as an reference between the schema and an object in some remote store.
  # The Store uses these references to keep track of the fixtures it has created.
  # The references are used by the locator to retrieve the fixture data from whatever
  # backend is being used.
  class Reference

    # A special key used to indicate that the a definition is currently building an
    # object for this locator_key. This is used to prevent circular dependencies.
    HOLDER_KEY = "__BUILDING_FIXTURE__"

    def self.holder(name)
      new(name, HOLDER_KEY)
    end

    attr_reader :name, :locator_key, :created_at, :options

    def initialize(name, locator_key, options = {})
      @name = name
      @locator_key = locator_key
      @created_at = Time.now.to_i
      @options = options
    end

    def holder?
      locator_key == HOLDER_KEY
    end

    def real?
      !holder?
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fixtury-1.0.0.beta3 lib/fixtury/reference.rb
fixtury-1.0.0.beta2 lib/fixtury/reference.rb
fixtury-1.0.0.beta1 lib/fixtury/reference.rb