Module: SolidCache::Connections

Defined in:
lib/solid_cache/connections.rb,
lib/solid_cache/connections/single.rb,
lib/solid_cache/connections/sharded.rb,
lib/solid_cache/connections/unmanaged.rb

Defined Under Namespace

Classes: Sharded, Single, Unmanaged

Class Method Summary collapse

Class Method Details

.from_config(options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/solid_cache/connections.rb', line 5

def self.from_config(options)
  if options.present? || SolidCache.configuration.sharded?
    case options
    when NilClass
      names = SolidCache.configuration.shard_keys
    when Array
      names = options.map(&:to_sym)
    end

    if (unknown_shards = names - SolidCache.configuration.shard_keys).any?
      raise ArgumentError, "Unknown #{"shard".pluralize(unknown_shards)}: #{unknown_shards.join(", ")}"
    end

    if names.size == 1
      Single.new(names.first)
    else
      Sharded.new(names)
    end
  else
    Unmanaged.new
  end
end