Module: Adapter::Cassanity
- Extended by:
- Forwardable
- Defined in:
- lib/adapter/cassanity.rb,
lib/adapter/cassanity/version.rb
Constant Summary collapse
- VERSION =
"0.5.0"
Instance Method Summary collapse
-
#clear(options = nil) ⇒ Object
Public.
-
#delete(key, options = nil) ⇒ Object
Public.
-
#read(key, options = nil) ⇒ Object
Public.
-
#update_arguments(operation_options, adapter_options, method_options) ⇒ Object
Private.
-
#where(key) ⇒ Object
Private.
-
#with_default_consistency(options) ⇒ Object
Private.
-
#write(key, attributes, options = nil) ⇒ Object
Public.
Instance Method Details
#clear(options = nil) ⇒ Object
Public
38 39 40 |
# File 'lib/adapter/cassanity.rb', line 38 def clear( = nil) @client.truncate end |
#delete(key, options = nil) ⇒ Object
Public
29 30 31 32 33 34 35 |
# File 'lib/adapter/cassanity.rb', line 29 def delete(key, = nil) = {where: where(key)} = with_default_consistency(@options[:delete]) arguments = update_arguments(, , ) @client.delete(arguments) end |
#read(key, options = nil) ⇒ Object
Public
10 11 12 13 14 15 16 17 |
# File 'lib/adapter/cassanity.rb', line 10 def read(key, = nil) = {where: where(key)} = with_default_consistency(@options[:read]) arguments = update_arguments(, , ) rows = @client.select(arguments) rows.empty? ? nil : rows.first end |
#update_arguments(operation_options, adapter_options, method_options) ⇒ Object
Private
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/adapter/cassanity.rb', line 49 def update_arguments(, , ) keys = .keys if !.nil? && !.empty? = .reject { |key| keys.include?(key) } .update() end if !.nil? && !.empty? = .reject { |key| keys.include?(key) } .update() end end |
#where(key) ⇒ Object
Private
43 44 45 46 |
# File 'lib/adapter/cassanity.rb', line 43 def where(key) primary_key = @options.fetch(:primary_key) {primary_key => key} end |
#with_default_consistency(options) ⇒ Object
Private
66 67 68 69 70 71 |
# File 'lib/adapter/cassanity.rb', line 66 def with_default_consistency() ||= {} [:using] ||= {} [:using][:consistency] ||= :quorum end |
#write(key, attributes, options = nil) ⇒ Object
Public
20 21 22 23 24 25 26 |
# File 'lib/adapter/cassanity.rb', line 20 def write(key, attributes, = nil) = {set: attributes, where: where(key)} = with_default_consistency(@options[:write]) arguments = update_arguments(, , ) @client.update(arguments) end |