Sha256: c5f3f5a9418f53731d67e7d722f052eb1f13cc8bbc97e526bafc725dedbd1c84
Contents?: true
Size: 1015 Bytes
Versions: 1
Compression:
Stored size: 1015 Bytes
Contents
require 'faye_shard/shard' require 'faye_shard/user/faye' class FayeShards class << self # Returns configuration for current Rails environment. # # * <tt>env</tt>:: Rails environment, defaults to +Rails.env+. # def config @config ||= YAML.load(File.read(Rails.root.to_s + "/config/faye.yml")) @config[Rails.env] end # Returns the object which represents a connection to a specific shard. The object is effectively # an instance of +FayeShards::Shard+ class which can be found in this gem. # # * <tt>id</tt>:: Id (an integer, string of whatever) to perform sharding based on. # def shard(id) @shards ||= {} shard_configs = config["shards"] @shards[id % shard_configs.size] ||= FayeShard::Shard.new(shard_configs[id % shard_configs.size]) end # Returns all configured shards # def all_shards @all_shards ||= config["shards"].map{ |shard_config| FayeShard::Shard.new(shard_config) } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
faye_shards-0.1.2 | lib/faye_shards.rb |