grumlin 0.1.0 → 0.3.0

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: 49bd6724ef81d1ac81e11d07d353b1f474ffaa60616dfab291d3f43ae81f95aa
4
- data.tar.gz: 8023ce32bede0aadaed1c0495654b5d2bec8e244deb007b766561254b7c9b69e
3
+ metadata.gz: e532964db5d5afd11d89978a132a5f4f7d1a4d98c740f639acadac260c93be89
4
+ data.tar.gz: 9015cb71bbab17895d8809dc7ff514b90e9d1ceb81ed6a9eec446a0db7ec0994
5
5
  SHA512:
6
- metadata.gz: 434d14086ce4814684de2f414ba9eb9e5dd24f5a96b4acb0861b526f1515ad13dff96d5460d871e8373335f38baae013c248815d08e0ff2616a6ace873e1316a
7
- data.tar.gz: e5fd01d1b8743d263097449f1f17ae515073e6253c7d7cfc11e65e923870b695c5d0a482105a41c20cea2a401f4cd2ffab3282defa74d0e9ed739e60fd850ead
6
+ metadata.gz: a4295b9e6041726c36c05cc0aed94a645e8d7103c99351dfadef7077f14037b81daf87a4ffb1fd48105d8c1fa888e96ce173aa3be42c9b35ec58de3e289c01ed
7
+ data.tar.gz: 51824ca159be63be91fc798b40777a25d55f0ce423b07a9ce4ce9880002e94b4e4196bc0d92b4ca84bee86356f17fd90f3cc2dd9daa594f906fc2e93f11be422
@@ -1,18 +1,73 @@
1
1
  name: Ruby
2
2
 
3
- on: [push,pull_request]
3
+ on: [push, pull_request]
4
4
 
5
5
  jobs:
6
- build:
6
+ lint:
7
7
  runs-on: ubuntu-latest
8
8
  steps:
9
- - uses: actions/checkout@v2
10
- - name: Set up Ruby
11
- uses: ruby/setup-ruby@v1
12
- with:
13
- ruby-version: 3.0.1
14
- - name: Run the default task
15
- run: |
16
- gem install bundler -v 2.2.15
17
- bundle install
18
- bundle exec rake
9
+ - uses: actions/checkout@v2
10
+
11
+ - uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0
14
+ bundler-cache: true
15
+
16
+ - name: Run the default task
17
+ run: |
18
+ gem install bundler -v 2.2.15
19
+ bundle install
20
+ bundle exec rubocop
21
+ test:
22
+ runs-on: ubuntu-latest
23
+ strategy:
24
+ matrix:
25
+ ruby: [2.6, 2.7, 3.0]
26
+ steps:
27
+ - uses: actions/checkout@v2
28
+
29
+ - uses: ruby/setup-ruby@v1
30
+ with:
31
+ ruby-version: ${{ matrix.ruby }}
32
+ bundler-cache: true
33
+
34
+ - name: Start Gremlin server
35
+ run: |
36
+ docker-compose up -d --build
37
+ sleep 3
38
+
39
+ - name: Install deps
40
+ run: |
41
+ gem install bundler -v 2.2.15
42
+ bundle install
43
+
44
+ - name: Run tests
45
+ run: bundle exec rspec
46
+ publish:
47
+ runs-on: ubuntu-latest
48
+ needs:
49
+ - lint
50
+ - test
51
+ if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
52
+ steps:
53
+ - uses: actions/checkout@v2
54
+
55
+ - uses: ruby/setup-ruby@v1
56
+ with:
57
+ ruby-version: 3.0
58
+ bundler-cache: true
59
+
60
+ - name: Build gem
61
+ run: gem build
62
+
63
+ - name: Create credentials
64
+ run: |
65
+ mkdir ~/.gem
66
+ cat << EOF > ~/.gem/credentials
67
+ ---
68
+ :rubygems_api_key: ${{ secrets.rubygems_api_key }}
69
+ EOF
70
+ chmod 0600 /home/runner/.gem/credentials
71
+
72
+ - name: Push gem
73
+ run: gem push *gem
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.gem
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
data/.overcommit.yml ADDED
@@ -0,0 +1,8 @@
1
+ PreCommit:
2
+ RuboCop:
3
+ enabled: true
4
+ on_warn: fail # Treat all warnings as failures
5
+
6
+ PrePush:
7
+ RSpec:
8
+ enabled: true
data/.rubocop.yml CHANGED
@@ -33,3 +33,6 @@ RSpec/NestedGroups:
33
33
 
34
34
  RSpec/ExampleLength:
35
35
  Enabled: false
36
+
37
+ Style/MultilineBlockChain:
38
+ Enabled: false
data/Gemfile CHANGED
@@ -4,8 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
- gem "rake"
8
-
7
+ gem "nokogiri"
9
8
  gem "rubocop"
10
9
  gem "rubocop-performance"
11
10
  gem "rubocop-rspec"
@@ -14,5 +13,6 @@ gem "solargraph"
14
13
 
15
14
  gem "async-rspec"
16
15
  gem "factory_bot"
16
+ gem "overcommit"
17
17
  gem "rspec"
18
18
  gem "simplecov"
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grumlin (0.1.0)
5
- async-websocket (~> 0.18)
4
+ grumlin (0.3.0)
5
+ async-pool (~> 0.3)
6
+ async-websocket (~> 0.19)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -14,33 +15,34 @@ GEM
14
15
  tzinfo (~> 2.0)
15
16
  zeitwerk (~> 2.3)
16
17
  ast (2.4.2)
17
- async (1.29.0)
18
+ async (1.30.1)
18
19
  console (~> 1.10)
19
20
  nio4r (~> 2.3)
20
21
  timers (~> 4.1)
21
- async-http (0.56.2)
22
- async (~> 1.25)
23
- async-io (~> 1.28)
24
- async-pool (~> 0.2)
22
+ async-http (0.56.5)
23
+ async (>= 1.25)
24
+ async-io (>= 1.28)
25
+ async-pool (>= 0.2)
25
26
  protocol-http (~> 0.22.0)
26
27
  protocol-http1 (~> 0.14.0)
27
28
  protocol-http2 (~> 0.14.0)
28
- async-io (1.31.0)
29
- async (~> 1.14)
30
- async-pool (0.3.6)
31
- async (~> 1.25)
29
+ async-io (1.32.2)
30
+ async
31
+ async-pool (0.3.8)
32
+ async (>= 1.25)
32
33
  async-rspec (1.16.0)
33
34
  rspec (~> 3.0)
34
35
  rspec-files (~> 1.0)
35
36
  rspec-memory (~> 1.0)
36
- async-websocket (0.18.0)
37
+ async-websocket (0.19.0)
37
38
  async-http (~> 0.54)
38
39
  async-io (~> 1.23)
39
40
  protocol-websocket (~> 0.7.0)
40
- backport (1.1.2)
41
+ backport (1.2.0)
41
42
  benchmark (0.1.1)
43
+ childprocess (4.0.0)
42
44
  concurrent-ruby (1.1.8)
43
- console (1.12.0)
45
+ console (1.13.1)
44
46
  fiber-local
45
47
  diff-lcs (1.4.4)
46
48
  docile (1.4.0)
@@ -50,6 +52,7 @@ GEM
50
52
  fiber-local (1.0.0)
51
53
  i18n (1.8.10)
52
54
  concurrent-ruby (~> 1.0)
55
+ iniparse (1.5.0)
53
56
  jaro_winkler (1.5.4)
54
57
  kramdown (2.3.1)
55
58
  rexml
@@ -57,13 +60,16 @@ GEM
57
60
  kramdown (~> 2.0)
58
61
  minitest (5.14.4)
59
62
  nio4r (2.5.7)
60
- nokogiri (1.11.5-x86_64-linux)
63
+ nokogiri (1.11.7-x86_64-linux)
61
64
  racc (~> 1.4)
65
+ overcommit (0.57.0)
66
+ childprocess (>= 0.6.3, < 5)
67
+ iniparse (~> 1.4)
62
68
  parallel (1.20.1)
63
69
  parser (3.0.1.1)
64
70
  ast (~> 2.4.1)
65
71
  protocol-hpack (1.4.2)
66
- protocol-http (0.22.0)
72
+ protocol-http (0.22.5)
67
73
  protocol-http1 (0.14.1)
68
74
  protocol-http (~> 0.22)
69
75
  protocol-http2 (0.14.2)
@@ -74,7 +80,6 @@ GEM
74
80
  protocol-http1 (~> 0.2)
75
81
  racc (1.5.2)
76
82
  rainbow (3.0.0)
77
- rake (13.0.3)
78
83
  regexp_parser (2.1.1)
79
84
  reverse_markdown (2.0.0)
80
85
  nokogiri
@@ -96,16 +101,16 @@ GEM
96
101
  diff-lcs (>= 1.2.0, < 2.0)
97
102
  rspec-support (~> 3.10.0)
98
103
  rspec-support (3.10.2)
99
- rubocop (1.15.0)
104
+ rubocop (1.16.1)
100
105
  parallel (~> 1.10)
101
106
  parser (>= 3.0.0.0)
102
107
  rainbow (>= 2.2.2, < 4.0)
103
108
  regexp_parser (>= 1.8, < 3.0)
104
109
  rexml
105
- rubocop-ast (>= 1.5.0, < 2.0)
110
+ rubocop-ast (>= 1.7.0, < 2.0)
106
111
  ruby-progressbar (~> 1.7)
107
112
  unicode-display_width (>= 1.4.0, < 3.0)
108
- rubocop-ast (1.5.0)
113
+ rubocop-ast (1.7.0)
109
114
  parser (>= 3.0.1.1)
110
115
  rubocop-performance (1.11.3)
111
116
  rubocop (>= 1.7.0, < 2.0)
@@ -120,10 +125,11 @@ GEM
120
125
  simplecov_json_formatter (~> 0.1)
121
126
  simplecov-html (0.12.3)
122
127
  simplecov_json_formatter (0.1.3)
123
- solargraph (0.40.4)
124
- backport (~> 1.1)
128
+ solargraph (0.43.0)
129
+ backport (~> 1.2)
125
130
  benchmark
126
131
  bundler (>= 1.17.2)
132
+ diff-lcs (~> 1.4)
127
133
  e2mmap
128
134
  jaro_winkler (~> 1.5)
129
135
  kramdown (~> 2.3)
@@ -150,7 +156,8 @@ DEPENDENCIES
150
156
  async-rspec
151
157
  factory_bot
152
158
  grumlin!
153
- rake
159
+ nokogiri
160
+ overcommit
154
161
  rspec
155
162
  rubocop
156
163
  rubocop-performance
data/bin/console CHANGED
@@ -5,9 +5,12 @@ require "bundler/setup"
5
5
  require "grumlin"
6
6
  require "irb"
7
7
 
8
+ Grumlin.configure do |config|
9
+ config.url = ENV["GREMLIN_URL"] || "ws://localhost:8182/gremlin"
10
+ end
11
+
8
12
  Async do
9
- client = Grumlin::Client.new("ws://localhost:8182/gremlin", mode: :bytecode)
10
- g = Grumlin::Traversal.new(client)
13
+ g = Grumlin::Traversal.new
11
14
 
12
15
  IRB.setup(nil)
13
16
  workspace = IRB::WorkSpace.new(binding)
@@ -16,5 +19,5 @@ Async do
16
19
  rescue StandardError
17
20
  raise
18
21
  ensure
19
- client.disconnect
22
+ Grumlin.config.default_pool.close
20
23
  end
data/bin/setup CHANGED
@@ -4,5 +4,6 @@ IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
6
  bundle install
7
+ bundle exec overcommit --sign
7
8
 
8
9
  # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ version: "3"
2
+ services:
3
+ gremlin_server:
4
+ build: gremlin_server
5
+ ports:
6
+ - "8182:8182"
@@ -0,0 +1,3 @@
1
+ FROM tinkerpop/gremlin-server
2
+
3
+ ADD tinkergraph-empty.properties /opt/gremlin-server/conf/
@@ -0,0 +1,3 @@
1
+ gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
2
+ gremlin.tinkergraph.vertexIdManager=ANY
3
+ gremlin.tinkergraph.edgeIdManager=ANY
data/grumlin.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Gleb Sinyavskiy"]
9
9
  spec.email = ["zhulik.gleb@gmail.com"]
10
10
 
11
- spec.summary = "A ruby client for Gremlin query language."
12
- spec.description = "A ruby client for Gremlin query language."
11
+ spec.summary = "Gremlin query language DSL for Ruby."
12
+ spec.description = "Gremlin query language DSL for Ruby."
13
13
  spec.homepage = "https://github.com/zhulik/grumlin"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
@@ -23,5 +23,6 @@ Gem::Specification.new do |spec|
23
23
  end
24
24
  spec.require_paths = ["lib"]
25
25
 
26
- spec.add_dependency "async-websocket", "~> 0.18"
26
+ spec.add_dependency "async-pool", "~> 0.3"
27
+ spec.add_dependency "async-websocket", "~> 0.19"
27
28
  end
data/lib/grumlin.rb CHANGED
@@ -4,21 +4,64 @@ require "securerandom"
4
4
  require "json"
5
5
 
6
6
  require "async"
7
+ require "async/pool"
8
+ require "async/pool/resource"
9
+ require "async/pool/controller"
7
10
  require "async/queue"
11
+ require "async/barrier"
8
12
  require "async/http/endpoint"
9
13
  require "async/websocket/client"
10
14
 
11
15
  require_relative "grumlin/version"
12
16
  require_relative "grumlin/exceptions"
13
17
 
18
+ require_relative "grumlin/transport"
19
+ require_relative "grumlin/client"
20
+
14
21
  require_relative "grumlin/vertex"
15
22
  require_relative "grumlin/edge"
23
+ require_relative "grumlin/path"
16
24
  require_relative "grumlin/typing"
17
- require_relative "grumlin/client"
18
25
  require_relative "grumlin/traversal"
19
- require_relative "grumlin/step"
26
+ require_relative "grumlin/request_dispatcher"
20
27
  require_relative "grumlin/translator"
21
- require_relative "grumlin/traversing_context"
28
+
29
+ require_relative "grumlin/anonymous_step"
30
+ require_relative "grumlin/step"
31
+
32
+ require_relative "grumlin/t"
33
+ require_relative "grumlin/order"
34
+ require_relative "grumlin/u"
35
+ require_relative "grumlin/p"
36
+ require_relative "grumlin/pop"
37
+ require_relative "grumlin/sugar"
22
38
 
23
39
  module Grumlin
40
+ class Config
41
+ attr_accessor :url, :pool_size, :client_concurrency
42
+
43
+ # For some reason, client_concurrency must be greather pool_size
44
+ def initialize
45
+ @pool_size = 10
46
+ @client_concurrency = 20
47
+ end
48
+
49
+ def default_pool
50
+ @default_pool ||= Async::Pool::Controller.new(Grumlin::Client::PoolResource, limit: pool_size)
51
+ end
52
+
53
+ def reset!
54
+ @default_pool = nil
55
+ end
56
+ end
57
+
58
+ class << self
59
+ def configure
60
+ yield config
61
+ end
62
+
63
+ def config
64
+ @config ||= Config.new
65
+ end
66
+ end
24
67
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Grumlin
4
+ class AnonymousStep
5
+ attr_reader :name, :args
6
+
7
+ def initialize(name, *args, previous_steps: [])
8
+ @name = name
9
+ @previous_steps = previous_steps
10
+ @args = args
11
+ end
12
+
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|
16
+ define_method step do |*args|
17
+ add_step(step, args, previous_steps: steps)
18
+ end
19
+ end
20
+
21
+ alias addVertex addV
22
+ alias addEdge addE
23
+
24
+ def inspect
25
+ @inspect ||= to_bytecode.to_s
26
+ end
27
+
28
+ alias to_s inspect
29
+
30
+ def to_bytecode
31
+ @to_bytecode ||= (@previous_steps.last&.to_bytecode || []) + [Translator.to_bytecode(self)]
32
+ end
33
+
34
+ def steps
35
+ (@previous_steps + [self])
36
+ end
37
+
38
+ private
39
+
40
+ def add_step(step_name, args, previous_steps:)
41
+ self.class.new(step_name, *args, previous_steps: previous_steps)
42
+ end
43
+ end
44
+ end