Sha256: 7d135edb5473bcae73e5270f4f198d42c476ddfdc7e40950cc6d37d60971fb22

Contents?: true

Size: 896 Bytes

Versions: 2

Compression:

Stored size: 896 Bytes

Contents

module Tako
  module ActiveRecordExt
    module CollectionProxy
      SHARDED_METHODS = [
        :any?,
        :build,
        :count,
        :create,
        :create!,
        :concat,
        :delete,
        :delete_all,
        :destroy,
        :destroy_all,
        :empty?,
        :find,
        :first,
        :include?,
        :last,
        :length,
        :many?,
        :pluck,
        :replace,
        :select,
        :size,
        :sum,
        :to_a,
        :uniq,
      ] & ActiveRecord::Associations::CollectionProxy.public_instance_methods

      def self.included(mod)
        mod.extend(ShardedMethods)
        mod.sharded_methods *SHARDED_METHODS
      end

      def current_shard
        @association.owner.current_shard
      end
    end
  end
end

ActiveRecord::Associations::CollectionProxy.class_eval do
  include Tako::ActiveRecordExt::CollectionProxy
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tako-0.4.1 lib/tako/active_record_ext/collection_proxy.rb
tako-0.4.0 lib/tako/active_record_ext/collection_proxy.rb