Sha256: 24e2b3de6ce52e316164330da410db732d4caf3543fa11e8fc4b4e435a4e55c1
Contents?: true
Size: 1.24 KB
Versions: 21
Compression:
Stored size: 1.24 KB
Contents
module CassandraObject module AsyncConnection extend ActiveSupport::Concern included do class_attribute :connection_spec class_eval do @@fiber_connections = {} def self.connection() @@fiber_connections[Fiber.current.object_id] ||= begin spec = connection_spec.dup if EM.reactor_running? require 'thrift_client/event_machine' spec[:thrift].merge!(:transport => Thrift::EventMachineTransport, :transport_wrapper => nil) end Cassandra.new(spec[:keyspace], spec[:servers], spec[:thrift]) end end def self.connection?() !!connection end def connection defined?(@connection) ? @connection : singleton_class.connection end def connection? !!connection end end end module ClassMethods DEFAULT_OPTIONS = { servers: "127.0.0.1:9160", thrift: {} } def establish_connection(spec) spec.reverse_merge!(DEFAULT_OPTIONS) spec[:thrift].symbolize_keys! self.connection_spec = spec end end end end
Version data entries
21 entries across 21 versions & 1 rubygems