lib/grumlin/shortcuts.rb in grumlin-0.19.7 vs lib/grumlin/shortcuts.rb in grumlin-0.20.0

- old
+ new

@@ -9,35 +9,28 @@ def inherited(subclass) super subclass.shortcuts_from(self) end - def shortcut(name, shortcut = nil, &block) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity + def shortcut(name, shortcut = nil, override: false, lazy: true, &block) name = name.to_sym - # TODO: blocklist of names to avoid conflicts with standard methods? - if Grumlin::Action::REGULAR_STEPS.include?(name) + lazy = false if override + + if Grumlin::Action::REGULAR_STEPS.include?(name) && !override raise ArgumentError, - "cannot use names of standard gremlin steps" + "overriding standard gremlin steps is not allowed, if you know what you're doing, pass `override: true`" end - if (shortcut.nil? && block.nil?) || (shortcut && block) - raise ArgumentError, "either shortcut or block must be passed" - end + raise ArgumentError, "either shortcut or block must be passed" if [shortcut, block].count(&:nil?) != 1 - shortcut ||= Shortcut.new(name, &block) - - raise ArgumentError, "shortcut '#{name}' already exists" if shortcuts.key?(name) && shortcuts[name] != shortcut - - shortcuts[name] = shortcut + shortcuts.add(name, shortcut || Shortcut.new(name, lazy: lazy, &block)) end def shortcuts_from(other_shortcuts) - other_shortcuts.shortcuts.each do |name, shortcut| - shortcut(name, shortcut) - end + shortcuts.add_from(other_shortcuts.shortcuts) end def shortcuts - @shortcuts ||= {} + @shortcuts ||= Storage.new end end end