Sha256: ec3345db95acf645c5b3620de50d7f29dc59237e3cbf7256cfa2121bad1ded92

Contents?: true

Size: 955 Bytes

Versions: 11

Compression:

Stored size: 955 Bytes

Contents

# frozen_string_literal: true

module Grumlin
  module 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::Action::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 || 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
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
grumlin-0.22.5 lib/grumlin/shortcuts.rb
grumlin-0.22.4 lib/grumlin/shortcuts.rb
grumlin-0.22.3 lib/grumlin/shortcuts.rb
grumlin-0.22.2 lib/grumlin/shortcuts.rb
grumlin-0.22.1 lib/grumlin/shortcuts.rb
grumlin-0.22.0 lib/grumlin/shortcuts.rb
grumlin-0.21.1 lib/grumlin/shortcuts.rb
grumlin-0.21.0 lib/grumlin/shortcuts.rb
grumlin-0.20.2 lib/grumlin/shortcuts.rb
grumlin-0.20.1 lib/grumlin/shortcuts.rb
grumlin-0.20.0 lib/grumlin/shortcuts.rb