class RailsNewsfeed::Relation

Public Class Methods

create(from, to, options = {}) click to toggle source

creates relations between two objects

# File lib/rails_newsfeed/relation.rb, line 20
def self.create(from, to, options = {})
  id = Cassandra::Uuid::Generator.new.now.to_s
  record = { id: id, from_class: from.class.name, from_id: from.id, to_class: to.class.name, to_id: to.id }
  return false unless Connection.insert(table_name, schema, record)
  Connection.insert(index_table_name, schema, record)
  return true unless options.key?(:side) && options[:side] == :both
  create(to, from)
end
delete(from, to, options = {}) click to toggle source

deletes relations between two objects

# File lib/rails_newsfeed/relation.rb, line 30
def self.delete(from, to, options = {})
  cond = { from_class: from.class.name, from_id: from.id, to_class: to.class.name, to_id: to.id }
  i = Connection.select(index_table_name, schema, '*', cond).first
  if i
    Connection.delete(table_name, schema, from_class: from.class.name, from_id: from.id, id: i['id'].to_s)
    Connection.delete(index_table_name, schema, cond)
  end
  return true unless options.key?(:side) && options[:side] == :both
  delete(to, from)
end
index_table_name() click to toggle source

gets index table name

# File lib/rails_newsfeed/relation.rb, line 9
def self.index_table_name
  "#{table_name}_index"
end
schema() click to toggle source

gets schema DO NOT override this method unless you know what you are doing

# File lib/rails_newsfeed/relation.rb, line 15
def self.schema
  { id: :uuid, from_class: :text, from_id: :text, to_class: :text, to_id: :text }
end
table_name() click to toggle source

gets table name

# File lib/rails_newsfeed/relation.rb, line 4
def self.table_name
  'relation'
end