Class Dissident::Cache
In: lib/nukumi2/vendor/dissident.rb
Parent: Object

Dissident::Cache keeps track of instantiated services by implementing a multiton instantiation scheme.

Methods

[]   fetch   method_missing   new   respond_to?  

External Aliases

to_s -> inspect
  Don‘t clutter up inspects.

Public Class methods

Create a new Cache for the container container.

[Source]

     # File lib/nukumi2/vendor/dissident.rb, line 233
233:     def initialize(container)
234:       @container = container
235:       @values = {}
236:     end

Public Instance methods

[](name, *args)

Alias for fetch

Instantiate the service name with the optional arguments args. Services that are of class Prototype will be evaluated on each request.

[Source]

     # File lib/nukumi2/vendor/dissident.rb, line 241
241:     def fetch(name, *args)
242:       @values.fetch(name) {
243:         @values[name] = {}
244:       }.fetch(args) {
245:         unless @container.respond_to? name
246:           raise MissingServiceError,
247:             "no service `#{name}' defined in #@container"
248:         end
249:         
250:         service = @container.__send__(name, *args)
251:         unless service.kind_of? Prototype
252:           @values[name][args] = service
253:         else
254:           service.call            # Evaluate the prototype, don't cache.
255:         end
256:       }
257:     end
method_missing(name, *args)

Alias for fetch

[Source]

     # File lib/nukumi2/vendor/dissident.rb, line 261
261:     def respond_to?(name)
262:       super or @container.respond_to? name
263:     end

[Validate]