Class: CassandraMapper::Persistence::ClassMethods::SimpleMutator

Inherits:
Object
  • Object
show all
Defined in:
lib/cassandra_mapper/persistence.rb

Instance Method Summary collapse

Instance Method Details

#from_simple(structure, timestamp) ⇒ Object



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/cassandra_mapper/persistence.rb', line 225

def from_simple(structure, timestamp)
  deletion = nil
  deletion_columns = nil
  structure.inject([]) do |list, pair|
    key,val = pair
    if val.nil?
      unless deletion
        deletion = CassandraThrift::Mutation.new(
          :deletion => CassandraThrift::Deletion.new(
            :super_column => nil,
            :timestamp    => timestamp,
            :predicate    => CassandraThrift::SlicePredicate.new(
              :column_names => (deletion_columns = [])
            )
          )
        )
        list << deletion
      end
      deletion_columns << key
    else
      list << CassandraThrift::Mutation.new(
        :column_or_supercolumn => CassandraThrift::ColumnOrSuperColumn.new(
          :column => CassandraThrift::Column.new(
            :name      => key,
            :value     => val,
            :timestamp => timestamp
          )
        )
      )
    end
    list
  end
end