Sha256: 53ed30bbc2d004f2f4be27af4652ad5d90399b1a5df81c4f76de9f227d92e5bd

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

class Rebat::Selector
  attr_reader :client

  def initialize(client)
    @client = client
    @query_list = []
  end

  def where(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_id)
    @query_list << create_query(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_id, Rebat::Thrift::QueryType::WHERE)
    return self
  end

  def union(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_id)
    @query_list << create_query(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_id, Rebat::Thrift::QueryType::UNION)
    return self
  end

  def intersect(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_id)
    @query_list << create_query(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_id, Rebat::Thrift::QueryType::INTERSECT)
    return self
  end

  def exclude(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_id)
    @query_list << create_query(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_id, Rebat::Thrift::QueryType::EXCLUDE)
    return self
  end

  def entries
    @client.send do |client|
      return client.selectQuery(@query_list)
    end
  end

  private
  attr_reader :query_list

  def create_query(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_id, qtype)
    edge = Rebat::Thrift::Edge.new

    edge.fromEntityId   = from_entity_id    unless from_entity_id.nil?
    edge.fromEntityType = from_entity_type  unless from_entity_type.nil?
    edge.toEntityId     = to_entity_id      unless to_entity_id.nil?
    edge.toEntityType   = to_entity_type    unless to_entity_type.nil?
    edge.relationId     = relation_id

    query = Rebat::Thrift::Query.new

    query.edge = edge
    query.qtype = qtype

    return query
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rebat-0.0.1 lib/rebat/selector.rb