Class Dissident::Cache
In: 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 dissident.rb, line 224
224:     def initialize(container)
225:       @container = container
226:       @values = {}
227:     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 dissident.rb, line 232
232:     def fetch(name, *args)
233:       @values.fetch(name) {
234:         @values[name] = {}
235:       }.fetch(args) {
236:         unless @container.respond_to? name
237:           raise MissingServiceError,
238:             "no service `#{name}' defined in #@container"
239:         end
240:         
241:         service = @container.__send__(name, *args)
242:         unless service.kind_of? Prototype
243:           @values[name][args] = service
244:         else
245:           service.call            # Evaluate the prototype, don't cache.
246:         end
247:       }
248:     end
method_missing(name, *args)

Alias for fetch

[Source]

     # File dissident.rb, line 252
252:     def respond_to?(name)
253:       super or @container.respond_to? name
254:     end

[Validate]