Module: ConnectionManager::Shards
- Defined in:
- lib/connection_manager/shards.rb
Instance Method Summary collapse
- #shard_class_names(*shard_class_names) ⇒ Object
-
#shards(*opts, &shards_block) ⇒ Object
Takes a block that is call on all available shards.
Instance Method Details
#shard_class_names(*shard_class_names) ⇒ Object
5 6 7 |
# File 'lib/connection_manager/shards.rb', line 5 def shard_class_names(*shard_class_names) @shard_class_names = shard_class_names end |
#shards(*opts, &shards_block) ⇒ Object
Takes a block that is call on all available shards.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/connection_manager/shards.rb', line 10 def shards(*opts,&shards_block) opts = {:include_self => true}.merge(opts.) raise ArgumentError, "shard_class_names have not been defined for #{self.class.name}" if @shard_class_names.length == 0 if block_given? results = [] @shard_class_names.each do |s| results << shards_block.call(s.constantize) end results << shards_block.call(self) if opts[:include_self] return results.flatten else raise ArgumentError, 'shards method requires a block.' end end |