Module: Mize::Configure

Included in:
Mize
Defined in:
lib/mize/configure.rb

Overview

Configuration helpers mixed in / extended onto the top-level Mize object.

Provides the block-based Mize.configure DSL and the default_cache accessor so users can swap the global cache backend.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_cache ⇒ Mize::CacheProtocol

The global default cache backend.

Every memoized object that has not been given an explicit cache instantiates a fresh copy (via prototype / "dup") of this backend. Reassign it to route all new memoized calls through a different store (Redis, Memcached, ...).

Returns:



14
15
16
# File 'lib/mize/configure.rb', line 14

def default_cache
  @default_cache
end

Instance Method Details

#cache(cache) ⇒ Mize::CacheProtocol

Set the default cache object to cache.

Intended for use inside a Mize.configure {} block.

Parameters:

Returns:



22
23
24
# File 'lib/mize/configure.rb', line 22

def cache(cache)
  self.default_cache = cache
end

#configure { ... } ⇒ Object

Configure Mize by evaluating block in the context of the Mize object.

Inside the block, cache (and the default_cache accessor) are called directly on Mize, so no receiver is required.

Examples:

Mize.configure do
  cache MyRedisCache.new
end

Yields:

  • The configuration block, evaluated via instance_eval.

Returns:

  • (Object) —

    The return value of block.



38
39
40
# File 'lib/mize/configure.rb', line 38

def configure(&block)
  instance_eval(&block)
end