Class: FayeShards

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

Class Method Summary collapse

Class Method Details

.all_shardsObject

Returns all configured shards



32
33
34
# File 'lib/faye_shards.rb', line 32

def all_shards
  @all_shards ||= config["shards"].map{ |shard_config| FayeShard::Shard.new(shard_config) }
end

.configObject

Returns configuration for current Rails environment.

* <tt>env</tt>:: Rails environment, defaults to +Rails.env+.


12
13
14
15
# 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) ⇒ Object

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.


22
23
24
25
26
27
28
# 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