Module: Wukong::Store::CassandraModel
- Defined in:
- lib/wukong/store/cassandra_model.rb,
lib/wukong/store/cassandra/streaming.rb
Overview
Barebones interface between a wukong class and a cassandra database
Class must somehow provide a class-level cassandra_db accessor that sets the @cassandra_db instance variable.
Defined Under Namespace
Modules: ClassMethods Classes: AvroWriter
Class Method Summary collapse
-
.included(base) ⇒ Object
The standard ‘inject class methods when module is included’ trick.
Instance Method Summary collapse
-
#save ⇒ Object
Store model to the DB.
-
#streaming_save ⇒ Object
Store model using avro writer.
-
#to_db_hash ⇒ Object
Flatten attributes for storage in the DB.
Class Method Details
.included(base) ⇒ Object
The standard ‘inject class methods when module is included’ trick
67 68 69 |
# File 'lib/wukong/store/cassandra_model.rb', line 67 def self.included base base.class_eval{ extend ClassMethods} end |
Instance Method Details
#save ⇒ Object
Store model to the DB
13 14 15 |
# File 'lib/wukong/store/cassandra_model.rb', line 13 def save self.class.insert key, self.to_db_hash end |
#streaming_save ⇒ Object
Store model using avro writer
9 10 11 |
# File 'lib/wukong/store/cassandra/streaming.rb', line 9 def streaming_save self.class.streaming_insert id, self end |
#to_db_hash ⇒ Object
Flatten attributes for storage in the DB.
-
omits elements whose value is nil
-
calls to_s on everything else
-
This means that blank strings are preserved;
-
and that false is saved as ‘false’
Override if you think something fancier than that should happen.
27 28 29 30 31 |
# File 'lib/wukong/store/cassandra_model.rb', line 27 def to_db_hash db_hsh = {} each_pair{|k,v| db_hsh[k.to_s] = v.to_s unless v.nil? } db_hsh end |