Sha256: ac39020d9d8ff13ca1b2077780fb248a9b94bfd5c891428fa028a0a3874950a0
Contents?: true
Size: 1.06 KB
Versions: 2
Compression:
Stored size: 1.06 KB
Contents
# encoding: utf-8 require "cassandra" module ROM::Cassandra # Wraps the external driver, responsible for sending CQL requests # to the Cassandra cluster # class Session # The regexp, describing the format of the allowed address of the cluster FORMAT = /\d{1,3}(\.\d{1,3}){3}(\:\d+)?/ # @!attribute [r] uri # # @return [Hash] the settings for the session # attr_reader :uri # Initializes a session to given cluster # # @param [Hash] options # def initialize(*options) @uri = extract(*options) @conn = ::Cassandra.cluster(uri).connect end # Sends the query to the Cassandra syncronously # # @param [#to_s] query # # @return [Array<Hash>] # def call(query) @conn.execute(query.to_s).to_a end private def extract(uri = { hosts: ["127.0.0.1"], port: 9042 }, hash = {}) return uri if uri.instance_of? Hash hosts, port = uri[FORMAT].split(":") { hosts: [hosts], port: port.to_i }.merge hash end end # class Session end # module ROM::Cassandra
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rom-cassandra-0.0.2 | lib/rom/cassandra/session.rb |
rom-cassandra-0.0.1 | lib/rom/cassandra/session.rb |