Sha256: f93c67bbb5c6ebdf31d1079dc6d697548cf303cfd69292b7f6818c54f0ec29e0

Contents?: true

Size: 1.9 KB

Versions: 2

Compression:

Stored size: 1.9 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_key)
    @query_list << create_query(from_entity_id, from_entity_type, to_entity_id, to_entity_type, @client.relations[relation_key], Rebat::Thrift::QueryType::WHERE)
    return self
  end

  def union(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_key)
    @query_list << create_query(from_entity_id, from_entity_type, to_entity_id, to_entity_type, @client.relations[relation_key], Rebat::Thrift::QueryType::UNION)
    return self
  end

  def intersect(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_key)
    @query_list << create_query(from_entity_id, from_entity_type, to_entity_id, to_entity_type, @client.relations[relation_key], Rebat::Thrift::QueryType::INTERSECT)
    return self
  end

  def exclude(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_key)
    @query_list << create_query(from_entity_id, from_entity_type, to_entity_id, to_entity_type, @client.relations[relation_key], Rebat::Thrift::QueryType::EXCLUDE)
    return self
  end

  def entries
    @client.sendQuery 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

2 entries across 2 versions & 1 rubygems

Version Path
rebat-0.1.3 lib/rebat/selector.rb
rebat-0.1.2 lib/rebat/selector.rb