Sha256: a41e0b5b951b4b1974b6cc25e2278b99700f66c661f883f26754ae6cea909b2d

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Grumlin
  class AnonymousStep
    attr_reader :name, :args

    # TODO: add other steps
    SUPPORTED_STEPS = %w[E V addE addV as by coalesce count dedup drop elementMap emit fold from group groupCount has
                         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: [])
      @name = name
      @previous_steps = previous_steps
      @args = args
    end

    SUPPORTED_STEPS.each do |step|
      define_method step do |*args|
        add_step(step, args, previous_steps: steps)
      end
    end

    def inspect
      @inspect ||= to_bytecode.to_s
    end

    alias to_s inspect

    def to_bytecode
      @to_bytecode ||= (@previous_steps.last&.to_bytecode || []) + [Translator.to_bytecode(self)]
    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)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grumlin-0.6.1 lib/grumlin/anonymous_step.rb
grumlin-0.6.0 lib/grumlin/anonymous_step.rb