Class: Cequel::Metal::Incrementer
- Defined in:
- lib/cequel/metal/incrementer.rb
Overview
Encapsulates a counter ‘UPDATE` operation comprising multiple increment or decrement operations
Instance Attribute Summary
Attributes inherited from Writer
Instance Method Summary collapse
-
#decrement(data) ⇒ void
Decrement one or more columns by given deltas.
-
#increment(data) ⇒ void
Increment one or more columns by given deltas.
Methods inherited from Writer
Methods included from Util::Forwardable
Constructor Details
This class inherits a constructor from Cequel::Metal::Writer
Instance Method Details
#decrement(data) ⇒ void
This method returns an undefined value.
Decrement one or more columns by given deltas
32 33 34 |
# File 'lib/cequel/metal/incrementer.rb', line 32 def decrement(data) increment(Hash[data.map { |column, count| [column, -count] }]) end |
#increment(data) ⇒ void
This method returns an undefined value.
Increment one or more columns by given deltas
18 19 20 21 22 23 24 |
# File 'lib/cequel/metal/incrementer.rb', line 18 def increment(data) data.each_pair do |column_name, delta| operator = delta < 0 ? '-' : '+' statements << "#{column_name} = #{column_name} #{operator} ?" bind_vars << delta.abs end end |