lib/grumlin/anonymous_step.rb in grumlin-0.7.0 vs lib/grumlin/anonymous_step.rb in grumlin-0.8.0
- old
+ new
@@ -1,44 +1,40 @@
# frozen_string_literal: true
module Grumlin
class AnonymousStep
- attr_reader :name, :args
+ attr_reader :name, :args, :previous_step
# TODO: add other steps
SUPPORTED_STEPS = %w[E V addE addV as by coalesce count dedup drop elementMap emit fold from group groupCount has
hasId hasLabel hasNot in inV label limit not order out outE path project property repeat select
to unfold valueMap values where].freeze
- def initialize(name, *args, previous_steps: [])
+ def initialize(name, *args, previous_step: nil)
@name = name
- @previous_steps = previous_steps
+ @previous_step = previous_step
@args = args
end
SUPPORTED_STEPS.each do |step|
- define_method step do |*args|
- add_step(step, args, previous_steps: steps)
+ define_method(step) do |*args|
+ add_step(step, args)
end
end
def inspect
- @inspect ||= to_bytecode.to_s
+ bytecode.inspect
end
alias to_s inspect
- def to_bytecode
- @to_bytecode ||= (@previous_steps.last&.to_bytecode || []) + [Translator.to_bytecode(self)]
+ def bytecode(no_return: false)
+ @bytecode ||= Bytecode.new(self, no_return: no_return)
end
- def steps
- (@previous_steps + [self])
- end
-
private
- def add_step(step_name, args, previous_steps:)
- self.class.new(step_name, *args, previous_steps: previous_steps)
+ def add_step(step_name, args)
+ self.class.new(step_name, *args, previous_step: self)
end
end
end