Module: Register

Defined in:
lib/register.rb,
lib/register/version.rb

Overview

Register is a tiny library that can be included in a module that is to become a Façade to several application globals via auto-generated module-level methods.

A good example is a register of several connections to either Redis or MemCached, for example you might have a short-term memcached connection with a short default expiration TTL, and a longer-living one that requires sweeping to clean. You could use Register to wrap access to these singletons in MyModule.cache_type accessors.

Usage

To create a register module, just include Register in any of your custom ruby modules:

require 'register'

module Cache
  include Register
end

Cache.register :rails, Rails.cache
Cache.register :durable, ActiveSupport::Cache::DalliStore.new(
  ENV['MEMCACHED_HOSTS'] ? ENV['MEMCACHED_HOSTS'].split(',') : %w[localhost:11211],
  namespace:      'v1',
  socket_timeout: 0.2,
  expires_in:     0, # never expire
  keepalive:      true,
  compress:       true,
  failover:       true
)

Cache.rails # => Rails.cache
Cache.durable # => DalliStore, etc.

Defined Under Namespace

Classes: AlreadyRegisteredError, NoSuchIdentifierError, RegisterError, ReservedIdentifierError

Constant Summary collapse

RESERVED =
(Register.methods + %i[for register keys values << add_method]).flatten.uniq.freeze
VERSION =
'0.5.5'.freeze