class Task::DataInterface::CassandraAdapter
Attributes
client[R]
tasks_table_name[R]
Public Class Methods
new(opts = {})
click to toggle source
@option opts [Cassava::Client] :client The Cassandra Client to use @option opts [Symbol] :tasks_table_name The table name of the cassandra table containing the tasks
Defaults to :tasks
# File lib/task/data_interface/cassandra_adapter.rb, line 12 def initialize(opts = {}) @client = opts[:client] @tasks_table_name = opts[:tasks_table_name] || :tasks end
Public Instance Methods
all(task_list)
click to toggle source
(see Interface
)
# File lib/task/data_interface/cassandra_adapter.rb, line 35 def all(task_list) read_pipe.push(:task_list => task_list).value end
delete(task_list, task_id)
click to toggle source
(see Interface
)
# File lib/task/data_interface/cassandra_adapter.rb, line 30 def delete(task_list, task_id) client.delete(:tasks).where(:task_list => task_list, :id => task_id).execute end
find(task_list, task_id)
click to toggle source
# File lib/task/data_interface/cassandra_adapter.rb, line 39 def find(task_list, task_id) read_pipe.push(:task_list => task_list, :id => task_id).value.first end
store(task)
click to toggle source
(see Interface
)
# File lib/task/data_interface/cassandra_adapter.rb, line 18 def store(task) pipeline = Pyper::Pipeline.new # Serialize the attributes to be stored pipeline << Pyper::Pipes::Model::AttributeSerializer.new # Store the serialized attributes in the tasks table pipeline << Pyper::Pipes::Cassandra::Writer.new(tasks_table_name, client) pipeline.push(task.as_hash) end
Private Instance Methods
read_pipe()
click to toggle source
# File lib/task/data_interface/cassandra_adapter.rb, line 45 def read_pipe pipeline = Pyper::Pipeline.new # Read items from cassandra, as determined by the args pushed into the pipeline pipeline << Pyper::Pipes::Cassandra::Reader.new(tasks_table_name, client) # Deserialize the data field into a hash pipeline << Pyper::Pipes::Model::AttributeDeserializer.new('data' => Hash) # Deserialize items into Task objects pipeline << TaskDeserializer pipeline end