Sha256: 747d5696c1b5f7effe266ff798cafe9b9864a3b187123b8ea5c5c08debadf30a

Contents?: true

Size: 1.29 KB

Versions: 7

Compression:

Stored size: 1.29 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_write_consistency
      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

7 entries across 7 versions & 1 rubygems

Version Path
sessionm-cassandra_object-2.3.6 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.3.5 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.3.4 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.3.3 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.3.2 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.3.1 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.3.0 lib/cassandra_object/consistency.rb