Sha256: 70162b5e31dee4264b5064b276abae67e93fb53874654cd350f1add8c0eb7d3a

Contents?: true

Size: 1.41 KB

Versions: 8

Compression:

Stored size: 1.41 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,
        :each_quorum => Cassandra::Consistency::EACH_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

8 entries across 8 versions & 1 rubygems

Version Path
sessionm-cassandra_object-2.7.5 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.7.4 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.7.3 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.7.2 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.7.1 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.7.0 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.6.1 lib/cassandra_object/consistency.rb
sessionm-cassandra_object-2.6.0 lib/cassandra_object/consistency.rb