Sha256: 5bfcb14c0d4e048785772a792a66402d2911bb9ed1a21e1ecc5768a364dfe489

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Grumlin
  class AnonymousStep
    attr_reader :name, :args

    def initialize(name, *args, previous_steps: [])
      @name = name
      @previous_steps = previous_steps
      @args = args
    end

    %w[addV addE V E limit count drop property valueMap select from to as order by has hasLabel values hasNot
       not outE groupCount label group in out fold unfold inV path dedup project coalesce repeat emit
       elementMap where].each do |step|
      define_method step do |*args|
        add_step(step, args, previous_steps: steps)
      end
    end

    alias addVertex addV
    alias addEdge addE

    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

5 entries across 5 versions & 1 rubygems

Version Path
grumlin-0.5.1 lib/grumlin/anonymous_step.rb
grumlin-0.5.0 lib/grumlin/anonymous_step.rb
grumlin-0.4.0 lib/grumlin/anonymous_step.rb
grumlin-0.3.0 lib/grumlin/anonymous_step.rb
grumlin-0.2.0 lib/grumlin/anonymous_step.rb