Class: Izanami::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/izanami/mapper.rb

Overview

Proxy around a Redis client. It handles the configuration and the namespaces.

Direct Known Subclasses

Izanami::Mappers::Command

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mapper

New Mapper client.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :namespace (String)

    the default namespace for all the keys.

  • :redis (Hash)

    Redis client options



16
17
18
19
20
# File 'lib/izanami/mapper.rb', line 16

def initialize(options = {})
  @options   = options.dup
  @redis     = @options.delete(:redis)
  @namespace = build_namespace(@options.delete(:namespace))
end

Instance Attribute Details

#namespaceObject (readonly)

Returns the value of attribute namespace.



9
10
11
# File 'lib/izanami/mapper.rb', line 9

def namespace
  @namespace
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/izanami/mapper.rb', line 9

def options
  @options
end

Instance Method Details

#clientRedis::Namespace

Redis client, with the namespace.

Returns:

  • (Redis::Namespace)


42
43
44
# File 'lib/izanami/mapper.rb', line 42

def client
  @client ||= initialize_client
end

#redisRedis::Client

Redis client, without the namespace.

Returns:

  • (Redis::Client)


35
36
37
# File 'lib/izanami/mapper.rb', line 35

def redis
  @redis ||= initialize_redis
end

#to_sObject

Inspect the mapper



57
58
59
60
61
62
# File 'lib/izanami/mapper.rb', line 57

def to_s(*)
  name = self.class.name
  info = redis.inspect

  "<#{name} connected to #{info} with @namespace=\"#{@namespace}\">"
end