lib/grumlin/step.rb in grumlin-0.1.3 vs lib/grumlin/step.rb in grumlin-0.2.0
- old
+ new
@@ -1,46 +1,31 @@
# frozen_string_literal: true
module Grumlin
- class Step
- attr_reader :client, :name, :args
+ class Step < AnonymousStep
+ attr_reader :client
- # TODO: add support for bytecode
def initialize(client, name, *args, previous_steps: [])
+ super(name, *args, previous_steps: previous_steps)
@client = client
- @name = name
- @previous_steps = previous_steps
- @args = args
end
- %w[addV addE V E limit count drop property valueMap select from to as].each do |step|
- define_method step do |*args|
- Step.new(@client, step, *args, previous_steps: steps)
- end
+ def next
+ @enum ||= toList.to_enum
+ @enum.next
end
- alias addVertex addV
- alias addEdge addE
-
- # TODO: add support for next
- # TODO: add support for iterate
- # TODO: memoization
def toList # rubocop:disable Naming/MethodName
- @client.query(*steps)
+ @toList ||= @client.submit(*steps) # rubocop:disable Naming/VariableName
end
- def inspect
- "<Step #{self}>" # TODO: substitute bindings
+ def iterate
+ @client.submit(*(steps + [nil]))
end
- # TODO: memoization
- def to_s(*)
- Translator.to_string(steps)
- end
+ private
- alias to_gremlin to_s
-
- def steps
- (@previous_steps + [self])
+ def add_step(step_name, args, previous_steps:)
+ self.class.new(@client, step_name, *args, previous_steps: previous_steps)
end
end
end