Sha256: 774b0b00c3ff4e53d40b3bc0e4f4ada4a6dc9d8495fa201ce6c27ed79530b0ce

Contents?: true

Size: 1.35 KB

Versions: 22

Compression:

Stored size: 1.35 KB

Contents

module CassandraObject
  module Consistency
    extend ActiveSupport::Concern

    included do
      class_attribute :write_consistency
      class_attribute :read_consistency
    end

    module ClassMethods
      THRIFT_LEVELS = {
        :one    => Cassandra::Consistency::ONE,
        :quorum => Cassandra::Consistency::QUORUM,
        :local_quorum => Cassandra::Consistency::LOCAL_QUORUM,
        :all    => Cassandra::Consistency::ALL
      }
      
      DEFAULT_OPTIONS = {
        :read_default => :quorum,
        :write_default => :quorum,
      }

      @@default_read_consistency = DEFAULT_OPTIONS[:read_default]
      @@default_write_consistency = DEFAULT_OPTIONS[:write_default]
      def set_default_consistencies(config)
        config = (config[:consistency] || {}).reverse_merge(DEFAULT_OPTIONS)
        @@default_read_consistency = config[:read_default].to_sym
        @@default_write_consistency = config[:write_default].to_sym
      end

      def thrift_read_consistency
        consistency = read_consistency || @@default_read_consistency
        THRIFT_LEVELS[consistency] || (raise "Invalid consistency level #{consistency}")
      end

      def thrift_write_consistency
        consistency = write_consistency || @@default_write_consistency
        THRIFT_LEVELS[consistency] || (raise "Invalid consistency level #{consistency}")
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
sessionm-cassandra_object-2.5.9 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.5.8 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.5.7 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.5.6 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.5.5 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.5.4 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.5.3 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.5.2 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.5.1 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.5.0 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.4.9 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.4.8 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.4.7 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.4.6 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.4.5 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.4.4 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.4.3 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.4.2 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.4.1 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.4.0 lib/cassandra_object/consistency.rb