Class: Virsandra::Connection
- Inherits:
-
Object
- Object
- Virsandra::Connection
- Extended by:
- Forwardable
- Defined in:
- lib/virsandra/connection.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
Instance Method Summary collapse
- #connect! ⇒ Object
- #disconnect! ⇒ Object
- #execute(query, consistency = nil) ⇒ Object
-
#initialize(config) ⇒ Connection
constructor
A new instance of Connection.
-
#method_missing(method, *args, &block) ⇒ Object
Delegate to CassandraCQL::Database handle.
- #respond_to?(method, include_private = false) ⇒ Boolean
Constructor Details
#initialize(config) ⇒ Connection
Returns a new instance of Connection.
8 9 10 11 12 |
# File 'lib/virsandra/connection.rb', line 8 def initialize(config) @config = config config.validate! connect! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Delegate to CassandraCQL::Database handle
29 30 31 32 |
# File 'lib/virsandra/connection.rb', line 29 def method_missing(method, *args, &block) return super unless @handle.respond_to?(method) @handle.send(method, *args, &block) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/virsandra/connection.rb', line 6 def config @config end |
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
6 7 8 |
# File 'lib/virsandra/connection.rb', line 6 def handle @handle end |
Instance Method Details
#connect! ⇒ Object
14 15 16 17 18 |
# File 'lib/virsandra/connection.rb', line 14 def connect! @handle = Cql::Client.connect(hosts: [@config.servers].flatten) @handle.use(@config.keyspace) @handle end |
#disconnect! ⇒ Object
20 21 22 |
# File 'lib/virsandra/connection.rb', line 20 def disconnect! @handle.close end |
#execute(query, consistency = nil) ⇒ Object
24 25 26 |
# File 'lib/virsandra/connection.rb', line 24 def execute(query, consistency = nil) @handle.execute(query, consistency || config.consistency) end |
#respond_to?(method, include_private = false) ⇒ Boolean
34 35 36 |
# File 'lib/virsandra/connection.rb', line 34 def respond_to?(method, include_private=false) @handle.respond_to?(method, include_private) || super(method, include_private) end |