Class: Flock::SelectOperations

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/flock/operations/select_operations.rb

Defined Under Namespace

Classes: Selecticon

Constant Summary collapse

EMPTY =
Flock::Operation.new do |page|
  [[], Flock::CursorEnd, Flock::CursorEnd]
end

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ SelectOperations

Returns a new instance of SelectOperations.



13
14
15
16
17
# File 'lib/flock/operations/select_operations.rb', line 13

def initialize(client)
  @client = client
  @service = client.service
  @selecticons = []
end

Instance Method Details

#edgesObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/flock/operations/select_operations.rb', line 50

def edges
  if @selecticons.any?
    @service.select_edges(to_thrift_edges).map do |results|
      # Note: pagination will not work for now.
      Flock::Operation.new do |page|
        [results.edges, Flock::CursorEnd, Flock::CursorEnd]
      end
    end
  else
    EMPTY
  end
end

#operationObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/flock/operations/select_operations.rb', line 37

def operation
  if @selecticons.any?
    @service.select2(to_thrift_ids).map do |results|
      # Note: pagination will not work for now.
      Flock::Operation.new do |page|
        [results.ids.unpack("Q*"), Flock::CursorEnd, Flock::CursorEnd]
      end
    end
  else
    EMPTY
  end
end

#select(*query) ⇒ Object



19
20
21
22
23
# File 'lib/flock/operations/select_operations.rb', line 19

def select(*query)
  selecticon = Selecticon.new(Flock::QueryTerm.new(query, @client.graphs))
  @selecticons << selecticon
  selecticon
end

#to_thrift_edgesObject



25
26
27
28
29
# File 'lib/flock/operations/select_operations.rb', line 25

def to_thrift_edges
  @selecticons.map do |selecticon|
    selecticon.to_thrift_edges
  end
end

#to_thrift_idsObject



31
32
33
34
35
# File 'lib/flock/operations/select_operations.rb', line 31

def to_thrift_ids
  @selecticons.map do |selecticon|
    selecticon.to_thrift_ids
  end
end