class FayeShards

Public Class Methods

all_shards() click to toggle source

Returns all configured shards

# File lib/faye_shards.rb, line 32
def all_shards
  @all_shards ||= config["shards"].map{ |shard_config| FayeShard::Shard.new(shard_config) }
end
config() click to toggle source

Returns configuration for current Rails environment.

  • env

    Rails environment, defaults to Rails.env.

# File lib/faye_shards.rb, line 12
def config
  @config ||= YAML.load(File.read(Rails.root.to_s + "/config/faye.yml"))
  @config[Rails.env]
end
shard(id) click to toggle source

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.

  • id

    Id (an integer, string of whatever) to perform sharding based on.

# File lib/faye_shards.rb, line 22
def shard(id)
  @shards ||= {}

  shard_configs = config["shards"]

  @shards[id % shard_configs.size] ||= FayeShard::Shard.new(shard_configs[id % shard_configs.size])
end