Sha256: b1e36b4f13947a9a7b554ed338b5d239aa30ea05f6e6a08de2df23c0b3c7c3dd

Contents?: true

Size: 816 Bytes

Versions: 16

Compression:

Stored size: 816 Bytes

Contents

module ConnectionManager
  module Shards  
    @shard_class_names = []
    
    def shard_class_names(*shard_class_names)
      @shard_class_names = shard_class_names
    end 
    
    # Takes a block that is call on all available shards.
    def shards(*opts,&shards_block)
      opts = {:include_self => true}.merge(opts.extract_options!)
      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
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
connection_manager-1.0.4 lib/connection_manager/shards.rb
connection_manager-1.0.3 lib/connection_manager/shards.rb
connection_manager-1.0.2 lib/connection_manager/shards.rb
connection_manager-1.0.1 lib/connection_manager/shards.rb
connection_manager-0.3.11 lib/connection_manager/shards.rb
connection_manager-0.3.10 lib/connection_manager/shards.rb
connection_manager-0.3.9 lib/connection_manager/shards.rb
connection_manager-0.3.8 lib/connection_manager/shards.rb
connection_manager-0.3.7 lib/connection_manager/shards.rb
connection_manager-0.3.6 lib/connection_manager/shards.rb
connection_manager-0.3.5 lib/connection_manager/shards.rb
connection_manager-0.3.4 lib/connection_manager/shards.rb
connection_manager-0.3.3 lib/connection_manager/shards.rb
connection_manager-0.3.2 lib/connection_manager/shards.rb
connection_manager-0.3.1 lib/connection_manager/shards.rb
connection_manager-0.3.0 lib/connection_manager/shards.rb