lib/fixtury/store.rb in fixtury-1.0.0.beta3 vs lib/fixtury/store.rb in fixtury-1.0.0.beta4

- old
+ new

@@ -12,19 +12,13 @@ attr_reader :locator attr_reader :schema attr_reader :ttl - # Create a new store. - # @param locator [Fixtury::Locator, Symbol, NilClass] (see Fixtury::Locator#from) - # @param ttl [Integer, NilClass] The time-to-live for references in seconds. - # @param schema [Fixtury::Schema, NilClass] The schema to use for fixture definitions, defaults to the global schema. - # @return [Fixtury::Store] - def initialize(locator: nil, ttl: nil, schema: nil) + def initialize(schema: nil) @schema = schema || ::Fixtury.schema - @locator = ::Fixtury::Locator.from(locator) - @ttl = ttl&.to_i + @locator = ::Fixtury::Locator.from(::Fixtury.configuration.locator_backend) self.references = ::Fixtury.configuration.stored_references end def references @references ||= ::Concurrent::ThreadLocalVar.new({}) @@ -124,13 +118,14 @@ # Find the definition. dfn = schema.get!(search) raise ArgumentError, "#{search.inspect} must refer to a definition" unless dfn.acts_like?(:fixtury_definition) pathname = dfn.pathname + isokey = dfn.isolation_key # Ensure that if we're part of an isolation group, we load all the fixtures in that group. - maybe_load_isolation_dependencies(dfn.isolation_key) + maybe_load_isolation_dependencies(isokey) # See if we already hold a reference to the fixture. ref = references[pathname] # If the reference is a placeholder, we have a circular dependency. @@ -171,11 +166,17 @@ end log("store #{pathname}", level: LOG_LEVEL_DEBUG) locator_key = locator.dump(value, context: pathname) - references[pathname] = ::Fixtury::Reference.new(pathname, locator_key) + reference_opts = {} + reference_opts[:isolation_key] = isokey unless isokey == pathname + references[pathname] = ::Fixtury::Reference.new( + pathname, + locator_key, + **reference_opts + ) end value end alias [] get @@ -239,9 +240,13 @@ end # Log a contextual message using Fixtury.log def log(msg, level:) ::Fixtury.log(msg, level: level, name: "store") + end + + def ttl + ::Fixtury.configuration.reference_ttl&.to_i end end end