grumlin 0.15.4 → 0.15.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e796fc1b5bff2cb474d068ad2a05a2b8a195df1981842745d5c90798ab5e02b7
4
- data.tar.gz: 39cd9ac6bbedfb6a8707d306c6a6e0223856028162778bb665865e387dcf2bc3
3
+ metadata.gz: 195f614a2cbebbe43f6dd2aedb3aeb54891c4377f50f85f21f44ee3325c87f58
4
+ data.tar.gz: 0f0a3c0b5aa8f03fb4d613c406b08497685ee9fb4cbea2e8a0b99385f749ebf3
5
5
  SHA512:
6
- metadata.gz: 072df70e88f7192272cad5c6127740ef10d52b5057f42a557e9f4ea722e55f53d222025e7b4d7607666d4c5038d3e630abb55faec7f05c640efed53d442a2b57
7
- data.tar.gz: 32ac57244365458e56c9b2c2705500c87254ba523454817b67f88637e07444d5e0b2abfa361540693f0dedf578b7e5f346c8a2515e536c69ad86e5ee09fa7bf3
6
+ metadata.gz: 21a7d91e9ce0a9e143f4bba9bb15d4bd31f6337f72500038bf09cd471ab05535d9d3ade4cfba6d6b6d779e09600b6352ed83b3e4bd70aeadd1417e51ba663937
7
+ data.tar.gz: 9cd14a8f18b856eca87d3b51b48c3f3c0d8d454b76fae92466bd7aee370019bbbb0b398236187acfcfed2322520aa4a3aa68a0e6bfb8b02a073e27f0db3cf525
data/.rubocop.yml CHANGED
@@ -60,6 +60,9 @@ RSpec/MultipleExpectations:
60
60
  RSpec/DescribeClass:
61
61
  Enabled: false
62
62
 
63
+ RSpec/MultipleMemoizedHelpers:
64
+ Max: 7
65
+
63
66
  Style/WordArray:
64
67
  Exclude:
65
68
  - spec/**/*_spec.rb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grumlin (0.15.4)
4
+ grumlin (0.15.6)
5
5
  async-pool (~> 0.3)
6
6
  async-websocket (~> 0.19)
7
7
  oj (~> 3.12)
@@ -28,7 +28,7 @@ GEM
28
28
  protocol-http (~> 0.22.0)
29
29
  protocol-http1 (~> 0.14.0)
30
30
  protocol-http2 (~> 0.14.0)
31
- async-io (1.32.2)
31
+ async-io (1.33.0)
32
32
  async
33
33
  async-pool (0.3.9)
34
34
  async (>= 1.25)
data/lib/definitions.yml CHANGED
@@ -32,11 +32,14 @@ steps:
32
32
  - in
33
33
  - inE
34
34
  - inV
35
+ - inject
35
36
  - is
36
37
  - label
37
38
  - limit
38
39
  - map
40
+ - none
39
41
  - not
42
+ - option
40
43
  - or
41
44
  - order
42
45
  - out
@@ -68,6 +71,7 @@ steps:
68
71
  - V
69
72
  - addE
70
73
  - addV
74
+ - inject
71
75
  configuration:
72
76
  - withSack
73
77
  - withSideEffect
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Grumlin
4
+ class Shortcut
5
+ extend Forwardable
6
+
7
+ attr_reader :name, :block
8
+
9
+ def_delegator :@block, :arity
10
+ def_delegator :@block, :source_location
11
+
12
+ def initialize(name, &block)
13
+ @name = name
14
+ @block = block
15
+ end
16
+
17
+ def ==(other)
18
+ @name == other.name && @block == other.block
19
+ end
20
+
21
+ # TODO: to_s, inspect, preview
22
+
23
+ def apply(object, *args, **params)
24
+ object.instance_exec(*args, **params, &@block)
25
+ end
26
+ end
27
+ end
@@ -18,7 +18,7 @@ module Grumlin
18
18
 
19
19
  return wrap_result(@object.public_send(name, *args, **params)) if @object.respond_to?(name)
20
20
 
21
- return wrap_result(instance_exec(*args, **params, &@shortcuts[name])) if @shortcuts.key?(name)
21
+ return wrap_result(@shortcuts[name].apply(self, *args, **params)) if @shortcuts.key?(name)
22
22
 
23
23
  super
24
24
  end
@@ -18,7 +18,7 @@ module Grumlin
18
18
  subclass.shortcuts_from(self)
19
19
  end
20
20
 
21
- def shortcut(name, &block)
21
+ def shortcut(name, shortcut = nil, &block) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
22
22
  name = name.to_sym
23
23
  # TODO: blocklist of names to avoid conflicts with standard methods?
24
24
  if Grumlin::AnonymousStep::SUPPORTED_STEPS.include?(name)
@@ -26,14 +26,20 @@ module Grumlin
26
26
  "cannot use names of standard gremlin steps"
27
27
  end
28
28
 
29
- raise ArgumentError, "shortcut '#{name}' already exists" if shortcuts.key?(name) && shortcuts[name] != block
29
+ if (shortcut.nil? && block.nil?) || (shortcut && block)
30
+ raise ArgumentError, "either shortcut or block must be passed"
31
+ end
32
+
33
+ shortcut ||= Shortcut.new(name, &block)
34
+
35
+ raise ArgumentError, "shortcut '#{name}' already exists" if shortcuts.key?(name) && shortcuts[name] != shortcut
30
36
 
31
- shortcuts[name] = block
37
+ shortcuts[name] = shortcut
32
38
  end
33
39
 
34
40
  def shortcuts_from(other_shortcuts)
35
- other_shortcuts.shortcuts.each do |name, block|
36
- shortcut(name, &block)
41
+ other_shortcuts.shortcuts.each do |name, shortcut|
42
+ shortcut(name, shortcut)
37
43
  end
38
44
  end
39
45
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Grumlin
4
- VERSION = "0.15.4"
4
+ VERSION = "0.15.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grumlin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.4
4
+ version: 0.15.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gleb Sinyavskiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-20 00:00:00.000000000 Z
11
+ date: 2022-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-pool
@@ -115,6 +115,7 @@ files:
115
115
  - lib/grumlin/property.rb
116
116
  - lib/grumlin/repository.rb
117
117
  - lib/grumlin/request_dispatcher.rb
118
+ - lib/grumlin/shortcut.rb
118
119
  - lib/grumlin/shortcut_proxy.rb
119
120
  - lib/grumlin/shortcuts.rb
120
121
  - lib/grumlin/shortcuts/properties.rb