grumlin 0.5.0 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea9263ebc4f6303d3dc02ccd39c8dd04f2b46b434456edad4466a19ebe7dede2
4
- data.tar.gz: 84205bc8a2568987933d6cce5c576cbbf298700659b31d7435ecac1fde030029
3
+ metadata.gz: 6633f34f12f74200b56d3447e7b1cd5c2c4185cd4013a27157d809b2f97f01b2
4
+ data.tar.gz: a5b0c1b0f4a8ef813a48144b79b17a71c6385802ff77b46ef0fa703643790ac1
5
5
  SHA512:
6
- metadata.gz: 1fc512adc3e110cc6a6ed2f348a24b888b5f5443d566eb1f57bb3b56dad60529390f1c4c52b1391296f75a1ea4cd79dc70eb427c3f57b4bf4f4c6417e54bbe95
7
- data.tar.gz: 36029a741e2d89654cbb5a9ecd28213c7122e3ecc35cd030baa320af71bd238560d1e671a8b9d2aa1f4b40938d1787679b2166733b0ebc429d5a5a113142d3b2
6
+ metadata.gz: 6824448759e26af95f8753a1461fac6b0b66677e1cab723b8e79c76333c4e791b5364da81f87844b624796238a3e02b13065a7afb64d7a5ef7ca83a6e9c3e8be
7
+ data.tar.gz: d7ce1a01b2b50f90a317d270ad005561220fcb0f69da5036b97d20c88b2458e5dd7ea285c384cef5d5e9521ff077f2d43650985c1e928942e463cfc29bbdd247
data/.overcommit.yml CHANGED
@@ -3,6 +3,3 @@ PreCommit:
3
3
  enabled: true
4
4
  on_warn: fail # Treat all warnings as failures
5
5
 
6
- PrePush:
7
- RSpec:
8
- enabled: true
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.6.6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grumlin (0.5.0)
4
+ grumlin (0.6.2)
5
5
  async-pool (~> 0.3)
6
6
  async-websocket (~> 0.19)
7
7
 
@@ -70,7 +70,7 @@ GEM
70
70
  ast (~> 2.4.1)
71
71
  protocol-hpack (1.4.2)
72
72
  protocol-http (0.22.5)
73
- protocol-http1 (0.14.1)
73
+ protocol-http1 (0.14.2)
74
74
  protocol-http (~> 0.22)
75
75
  protocol-http2 (0.14.2)
76
76
  protocol-hpack (~> 1.4)
@@ -166,4 +166,4 @@ DEPENDENCIES
166
166
  solargraph
167
167
 
168
168
  BUNDLED WITH
169
- 2.2.15
169
+ 2.2.26
data/bin/console CHANGED
@@ -10,7 +10,7 @@ Grumlin.configure do |config|
10
10
  end
11
11
 
12
12
  Async do
13
- g = Grumlin::Traversal.new
13
+ include Grumlin::Sugar
14
14
 
15
15
  IRB.setup(nil)
16
16
  workspace = IRB::WorkSpace.new(binding)
@@ -4,23 +4,23 @@ module Grumlin
4
4
  class AnonymousStep
5
5
  attr_reader :name, :args
6
6
 
7
+ # TODO: add other steps
8
+ SUPPORTED_STEPS = %w[E V addE addV as by coalesce count dedup drop elementMap emit fold from group groupCount has
9
+ hasId hasLabel hasNot in inV label limit not order out outE path project property repeat select
10
+ to unfold valueMap values where].freeze
11
+
7
12
  def initialize(name, *args, previous_steps: [])
8
13
  @name = name
9
14
  @previous_steps = previous_steps
10
15
  @args = args
11
16
  end
12
17
 
13
- %w[addV addE V E limit count drop property valueMap select from to as order by has hasLabel values hasNot
14
- not outE groupCount label group in out fold unfold inV path dedup project coalesce repeat emit
15
- elementMap where].each do |step|
18
+ SUPPORTED_STEPS.each do |step|
16
19
  define_method step do |*args|
17
20
  add_step(step, args, previous_steps: steps)
18
21
  end
19
22
  end
20
23
 
21
- alias addVertex addV
22
- alias addEdge addE
23
-
24
24
  def inspect
25
25
  @inspect ||= to_bytecode.to_s
26
26
  end
@@ -26,6 +26,14 @@ module Grumlin
26
26
  def write(*args)
27
27
  @client.write(*args)
28
28
  end
29
+
30
+ def viable?
31
+ !closed?
32
+ end
33
+
34
+ def reusable?
35
+ !closed?
36
+ end
29
37
  end
30
38
 
31
39
  def initialize(url, parent: Async::Task.current, **client_options)
@@ -49,8 +57,10 @@ module Grumlin
49
57
  end
50
58
 
51
59
  def close
52
- @transport.close
53
- raise ResourceLeakError, "Request list is not empty: #{requests}" if @request_dispatcher.requests.any?
60
+ @transport&.close
61
+ if @request_dispatcher&.requests&.any?
62
+ raise ResourceLeakError, "Request list is not empty: #{@request_dispatcher.requests}"
63
+ end
54
64
 
55
65
  reset!
56
66
  end
data/lib/grumlin/order.rb CHANGED
@@ -2,16 +2,15 @@
2
2
 
3
3
  module Grumlin
4
4
  module Order
5
+ # TODO: share the code?
5
6
  class << self
6
- DESC = { "@type": "g:Order", "@value": "desc" }.freeze
7
- ASC = { "@type": "g:Order", "@value": "desc" }.freeze
7
+ %i[asc desc].each do |step|
8
+ define_method step do
9
+ name = "@#{step}"
10
+ return instance_variable_get(name) if instance_variable_defined?(name)
8
11
 
9
- def asc
10
- ASC
11
- end
12
-
13
- def desc
14
- DESC
12
+ instance_variable_set(name, TypedValue.new("Order", step))
13
+ end
15
14
  end
16
15
  end
17
16
  end
data/lib/grumlin/p.rb CHANGED
@@ -5,7 +5,7 @@ module Grumlin
5
5
  module P
6
6
  %w[within].each do |step|
7
7
  define_method step do |*args|
8
- { # TODO: replace with a class?
8
+ { # TODO: replace with a TypedValue?
9
9
  "@type": "g:P",
10
10
  "@value": { predicate: "within", value: { "@type": "g:List", "@value": args } }
11
11
  }
data/lib/grumlin/pop.rb CHANGED
@@ -2,26 +2,15 @@
2
2
 
3
3
  module Grumlin
4
4
  module Pop
5
+ # TODO: share the code?
5
6
  class << self
6
- FIRST = { "@type": "g:Pop", "@value": "first" }.freeze
7
- LAST = { "@type": "g:Pop", "@value": "last" }.freeze
8
- ALL = { "@type": "g:Pop", "@value": "all" }.freeze
9
- MIXED = { "@type": "g:Pop", "@value": "mixed" }.freeze
7
+ %i[first last all mixed].each do |step|
8
+ define_method step do
9
+ name = "@#{step}"
10
+ return instance_variable_get(name) if instance_variable_defined?(name)
10
11
 
11
- def first
12
- FIRST
13
- end
14
-
15
- def last
16
- LAST
17
- end
18
-
19
- def all
20
- ALL
21
- end
22
-
23
- def mixed
24
- MIXED
12
+ instance_variable_set(name, TypedValue.new("Pop", step))
13
+ end
25
14
  end
26
15
  end
27
16
  end
data/lib/grumlin/t.rb CHANGED
@@ -2,16 +2,15 @@
2
2
 
3
3
  module Grumlin
4
4
  module T
5
+ # TODO: share the code?
5
6
  class << self
6
- T_ID = { :@type => "g:T", :@value => "id" }.freeze # TODO: replace with a class?
7
- T_LABEL = { :@type => "g:T", :@value => "label" }.freeze # TODO: replace with a class?
7
+ %i[id label].each do |step|
8
+ define_method step do
9
+ name = "@#{step}"
10
+ return instance_variable_get(name) if instance_variable_defined?(name)
8
11
 
9
- def id
10
- T_ID
11
- end
12
-
13
- def label
14
- T_LABEL
12
+ instance_variable_set(name, TypedValue.new("T", step))
13
+ end
15
14
  end
16
15
  end
17
16
  end
@@ -20,6 +20,7 @@ module Grumlin
20
20
  private
21
21
 
22
22
  def arg_to_bytecode(arg)
23
+ return arg.to_bytecode if arg.is_a?(TypedValue)
23
24
  return arg unless arg.is_a?(AnonymousStep)
24
25
 
25
26
  args = arg.args.flatten.map do |a|
@@ -30,8 +31,11 @@ module Grumlin
30
31
 
31
32
  def arg_to_query_bytecode(arg)
32
33
  return ["none"] if arg.nil?
34
+ return arg.to_bytecode if arg.is_a?(TypedValue)
33
35
  return arg unless arg.is_a?(AnonymousStep)
34
36
 
37
+ # return arg.to_bytecode if arg.is_a?(TypedValue)
38
+
35
39
  args = arg.args.flatten.map do |a|
36
40
  a.instance_of?(AnonymousStep) ? Typing.to_bytecode(to_bytecode(a.steps)) : arg_to_query_bytecode(a)
37
41
  end
@@ -4,18 +4,17 @@ module Grumlin
4
4
  class Traversal
5
5
  attr_reader :connection
6
6
 
7
+ # TODO: add other start steps
8
+ SUPPORTED_START_STEPS = %w[E V addE addV].freeze
9
+
7
10
  def initialize(pool = Grumlin.config.default_pool)
8
11
  @pool = pool
9
12
  end
10
13
 
11
- # TODO: add other start steps
12
- %w[addV addE V E].each do |step|
14
+ SUPPORTED_START_STEPS.each do |step|
13
15
  define_method step do |*args|
14
16
  Step.new(@pool, step, *args)
15
17
  end
16
18
  end
17
-
18
- alias addVertex addV
19
- alias addEdge addE
20
19
  end
21
20
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Grumlin
4
+ # TODO: find a better name
5
+ class TypedValue
6
+ def initialize(type, value)
7
+ @type = type
8
+ @value = value
9
+ end
10
+
11
+ def inspect(*)
12
+ "#{@type}.#{@value}"
13
+ end
14
+
15
+ def to_bytecode
16
+ @to_bytecode ||= { "@type": "g:#{@type}", "@value": @value }
17
+ end
18
+ end
19
+ end
data/lib/grumlin/u.rb CHANGED
@@ -2,8 +2,11 @@
2
2
 
3
3
  module Grumlin
4
4
  module U
5
+ # TODO: add other start steps
6
+ SUPPORTED_START_STEPS = %w[V addV count has out unfold values].freeze
7
+
5
8
  class << self
6
- %w[addV V has count out values unfold].each do |step|
9
+ SUPPORTED_START_STEPS.each do |step|
7
10
  define_method step do |*args|
8
11
  AnonymousStep.new(step, *args)
9
12
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Grumlin
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.2"
5
5
  end
data/lib/grumlin.rb CHANGED
@@ -19,6 +19,7 @@ require_relative "grumlin/exceptions"
19
19
 
20
20
  require_relative "grumlin/transport"
21
21
  require_relative "grumlin/client"
22
+ require_relative "grumlin/typed_value"
22
23
 
23
24
  require_relative "grumlin/vertex"
24
25
  require_relative "grumlin/edge"
@@ -42,10 +43,9 @@ module Grumlin
42
43
  class Config
43
44
  attr_accessor :url, :pool_size, :client_concurrency, :client_factory
44
45
 
45
- # For some reason, client_concurrency must be greater than pool_size
46
46
  def initialize
47
47
  @pool_size = 10
48
- @client_concurrency = 20
48
+ @client_concurrency = 2
49
49
  @client_factory = ->(url, parent) { Grumlin::Client.new(url, parent: parent) }
50
50
  end
51
51
 
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.5.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gleb Sinyavskiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-23 00:00:00.000000000 Z
11
+ date: 2021-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-pool
@@ -50,6 +50,7 @@ files:
50
50
  - ".overcommit.yml"
51
51
  - ".rspec"
52
52
  - ".rubocop.yml"
53
+ - ".tool-versions"
53
54
  - CHANGELOG.md
54
55
  - CODE_OF_CONDUCT.md
55
56
  - Gemfile
@@ -82,6 +83,7 @@ files:
82
83
  - lib/grumlin/translator.rb
83
84
  - lib/grumlin/transport.rb
84
85
  - lib/grumlin/traversal.rb
86
+ - lib/grumlin/typed_value.rb
85
87
  - lib/grumlin/typing.rb
86
88
  - lib/grumlin/u.rb
87
89
  - lib/grumlin/version.rb