Class: Task::DataInterface::CassandraAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/task/data_interface/cassandra_adapter.rb

Defined Under Namespace

Classes: TaskDeserializer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ CassandraAdapter

Returns a new instance of CassandraAdapter.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :client (Cassava::Client)

    The Cassandra Client to use

  • :tasks_table_name (Symbol)

    The table name of the cassandra table containing the tasks Defaults to :tasks



12
13
14
15
# 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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/task/data_interface/cassandra_adapter.rb', line 7

def client
  @client
end

#tasks_table_nameObject (readonly)

Returns the value of attribute tasks_table_name.



7
8
9
# File 'lib/task/data_interface/cassandra_adapter.rb', line 7

def tasks_table_name
  @tasks_table_name
end

Instance Method Details

#all(task_list) ⇒ Object



35
36
37
# 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) ⇒ Object



30
31
32
# 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) ⇒ Object



39
40
41
# 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) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# 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