Sha256: 2779b9efc99e59b832ed0215305e7cd91179c9725f049ef21d1f77ee8daf0bd6

Contents?: true

Size: 902 Bytes

Versions: 15

Compression:

Stored size: 902 Bytes

Contents

# frozen_string_literal: true

module Grumlin::Shortcuts
  def self.extended(base)
    base.include(Grumlin::Expressions)
  end

  def inherited(subclass)
    super
    subclass.shortcuts_from(self)
  end

  def shortcut(name, shortcut = nil, override: false, lazy: true, &block)
    name = name.to_sym
    lazy = false if override

    if Grumlin::Step::REGULAR_STEPS.include?(name) && !override
      raise ArgumentError,
            "overriding standard gremlin steps is not allowed, if you know what you're doing, pass `override: true`"
    end

    raise ArgumentError, "either shortcut or block must be passed" if [shortcut, block].count(&:nil?) != 1

    shortcuts.add(name, shortcut || Grumlin::Shortcut.new(name, lazy: lazy, &block))
  end

  def shortcuts_from(other_shortcuts)
    shortcuts.add_from(other_shortcuts.shortcuts)
  end

  def shortcuts
    @shortcuts ||= Storage.new
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
grumlin-1.2.0 lib/grumlin/shortcuts.rb
grumlin-1.1.0 lib/grumlin/shortcuts.rb
grumlin-1.0.4 lib/grumlin/shortcuts.rb
grumlin-1.0.3 lib/grumlin/shortcuts.rb
grumlin-1.0.3.beta1 lib/grumlin/shortcuts.rb
grumlin-1.0.2 lib/grumlin/shortcuts.rb
grumlin-1.0.1 lib/grumlin/shortcuts.rb
grumlin-1.0.0 lib/grumlin/shortcuts.rb
grumlin-1.0.0.rc7 lib/grumlin/shortcuts.rb
grumlin-1.0.0.rc6 lib/grumlin/shortcuts.rb
grumlin-1.0.0.rc5 lib/grumlin/shortcuts.rb
grumlin-1.0.0.rc4 lib/grumlin/shortcuts.rb
grumlin-1.0.0.rc3 lib/grumlin/shortcuts.rb
grumlin-1.0.0.rc2 lib/grumlin/shortcuts.rb
grumlin-1.0.0.rc1 lib/grumlin/shortcuts.rb