grumlin 0.4.0 → 0.6.1

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: 11e434ab0f5cd463d357e69dd3cbf5083f85a1bdd32e4d2c96023ce262704020
4
- data.tar.gz: f24dd70f8b0abe9b370f77587d590802b32aa3e7b8a20380b9518004868cc6c7
3
+ metadata.gz: f6fc993f0e67d4bb4d7a97b3e2d64d692b334f862cb16c73349d222fdb21b95f
4
+ data.tar.gz: fb14fae220786a9f8b5654b271d344a24e09dcbaf565e998716e6465f6cc62f9
5
5
  SHA512:
6
- metadata.gz: 5bfbd0d4db9ef46d35839b8ca5654cdc1f5038ee2c4ca004b678471380095d1fb587fa89a8df0c5a4769e3943ceb4e0b88734b701593ccf1047a05ab85baaaf5
7
- data.tar.gz: a7d87e630e6b2076bedd079365e709018b3fc61f1577564c504593ffdeb4deab88f56d8785c30877489171b6c9d7fd245982475a75f4c639647c923e2ca296ef
6
+ metadata.gz: 14d22f47279dce78ccc70442ecaee502c8cf26547fa4a4ea679fb212699877e3bdda45af3fd957261bd4b77a2a410c5be20be9b80a6f239a3acb90d57e1daf40
7
+ data.tar.gz: 9b5fd78c4c8826e2459ed652b11bf611df64604086488a543687e8a8edb34913958df74dccd2bc0d08dc1eb2f1d0c608e0639c54aac956f5a164a66f8d1f2adb
@@ -1,6 +1,6 @@
1
1
  name: Ruby
2
2
 
3
- on: [push, pull_request]
3
+ on: [push]
4
4
 
5
5
  jobs:
6
6
  lint:
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/.rubocop.yml CHANGED
@@ -7,24 +7,44 @@ require:
7
7
  - rubocop-performance
8
8
  - rubocop-rspec
9
9
 
10
- Style/StringLiterals:
11
- Enabled: true
12
- EnforcedStyle: double_quotes
13
-
14
- Style/StringLiteralsInInterpolation:
15
- Enabled: true
16
- EnforcedStyle: double_quotes
17
-
18
- Style/Documentation:
19
- Enabled: false
20
-
21
10
  Layout/LineLength:
22
11
  Max: 120
12
+ Exclude:
13
+ - spec/**/*_spec.rb
23
14
 
24
15
  Metrics/BlockLength:
25
16
  Exclude:
26
17
  - spec/**/*_spec.rb
27
18
 
19
+ Metrics/MethodLength:
20
+ Max: 20
21
+
22
+ Metrics/ParameterLists:
23
+ Max: 6
24
+
25
+ Naming/MethodName:
26
+ IgnoredPatterns:
27
+ - toList
28
+ - inVLabel
29
+ - outVLabel
30
+ - inV
31
+ - outV
32
+
33
+ Naming/VariableName:
34
+ AllowedIdentifiers:
35
+ - inV
36
+ - outV
37
+ - inVLabel
38
+ - outVLabel
39
+
40
+ Naming/MethodParameterName:
41
+ AllowedNames:
42
+ - id
43
+ - inV
44
+ - outV
45
+ - inVLabel
46
+ - outVLabel
47
+
28
48
  RSpec/NamedSubject:
29
49
  Enabled: false
30
50
 
@@ -34,5 +54,26 @@ RSpec/NestedGroups:
34
54
  RSpec/ExampleLength:
35
55
  Enabled: false
36
56
 
57
+ RSpec/MultipleExpectations:
58
+ Enabled: false
59
+
60
+ RSpec/DescribeClass:
61
+ Enabled: false
62
+
63
+ Style/WordArray:
64
+ Exclude:
65
+ - spec/**/*_spec.rb
66
+
67
+ Style/StringLiterals:
68
+ Enabled: true
69
+ EnforcedStyle: double_quotes
70
+
71
+ Style/StringLiteralsInInterpolation:
72
+ Enabled: true
73
+ EnforcedStyle: double_quotes
74
+
75
+ Style/Documentation:
76
+ Enabled: false
77
+
37
78
  Style/MultilineBlockChain:
38
- Enabled: false
79
+ Enabled: false
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.4.0)
4
+ grumlin (0.6.1)
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)
data/lib/async/channel.rb CHANGED
@@ -45,7 +45,7 @@ module Async
45
45
  end
46
46
  end
47
47
 
48
- def each # rubocop:disable Metrics/MethodLength
48
+ def each
49
49
  raise(ChannelClosedError, "Cannot receive from a closed channel") if closed?
50
50
 
51
51
  @queue.each do |type, payload|
@@ -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
+ hasLabel hasNot in inV label limit not order out outE path project property repeat select to
10
+ 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
@@ -49,8 +49,10 @@ module Grumlin
49
49
  end
50
50
 
51
51
  def close
52
- @transport.close
53
- raise ResourceLeakError, "Request list is not empty: #{requests}" if @request_dispatcher.requests.any?
52
+ @transport&.close
53
+ if @request_dispatcher&.requests&.any?
54
+ raise ResourceLeakError, "Request list is not empty: #{@request_dispatcher.requests}"
55
+ end
54
56
 
55
57
  reset!
56
58
  end
@@ -60,7 +62,7 @@ module Grumlin
60
62
  end
61
63
 
62
64
  # TODO: support yielding
63
- def write(*args) # rubocop:disable Metrics/MethodLength
65
+ def write(*args)
64
66
  raise NotConnectedError unless connected?
65
67
 
66
68
  request_id = SecureRandom.uuid
data/lib/grumlin/edge.rb CHANGED
@@ -1,11 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Naming/VariableName,Naming/MethodParameterName,Naming/MethodName
4
3
  module Grumlin
5
4
  class Edge
6
5
  attr_reader :label, :id, :inVLabel, :outVLabel, :inV, :outV
7
6
 
8
- def initialize(label:, id:, inVLabel:, outVLabel:, inV:, outV:) # rubocop:disable Metrics/ParameterLists
7
+ def initialize(label:, id:, inVLabel:, outVLabel:, inV:, outV:)
9
8
  @label = label
10
9
  @id = Typing.cast(id)
11
10
  @inVLabel = inVLabel
@@ -24,4 +23,3 @@ module Grumlin
24
23
  alias to_s inspect
25
24
  end
26
25
  end
27
- # rubocop:enable Naming/MethodParameterName,Naming/VariableName,Naming/MethodName
data/lib/grumlin/order.rb CHANGED
@@ -2,21 +2,16 @@
2
2
 
3
3
  module Grumlin
4
4
  module Order
5
- module Order
6
- DESC = { "@type": "g:Order", "@value": "desc" }.freeze
7
- ASC = { "@type": "g:Order", "@value": "desc" }.freeze
5
+ # TODO: share the code?
6
+ class << self
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
- extend self # rubocop:disable Style/ModuleFunction
10
-
11
- def asc
12
- ASC
13
- end
14
-
15
- def desc
16
- DESC
12
+ instance_variable_set(name, TypedValue.new("Order", step))
13
+ end
17
14
  end
18
15
  end
19
-
20
- extend Order
21
16
  end
22
17
  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,31 +2,16 @@
2
2
 
3
3
  module Grumlin
4
4
  module Pop
5
- module Pop
6
- extend self # rubocop:disable Style/ModuleFunction
5
+ # TODO: share the code?
6
+ class << self
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)
7
11
 
8
- FIRST = { "@type": "g:Pop", "@value": "first" }.freeze
9
- LAST = { "@type": "g:Pop", "@value": "last" }.freeze
10
- ALL = { "@type": "g:Pop", "@value": "all" }.freeze
11
- MIXED = { "@type": "g:Pop", "@value": "mixed" }.freeze
12
-
13
- def first
14
- FIRST
15
- end
16
-
17
- def last
18
- LAST
19
- end
20
-
21
- def all
22
- ALL
23
- end
24
-
25
- def mixed
26
- MIXED
12
+ instance_variable_set(name, TypedValue.new("Pop", step))
13
+ end
27
14
  end
28
15
  end
29
-
30
- extend Pop
31
16
  end
32
17
  end
@@ -36,7 +36,7 @@ module Grumlin
36
36
 
37
37
  # builds a response object, when it's ready sends it to the client via a channel
38
38
  # TODO: sometimes response does not include requestID, no idea how to handle it so far.
39
- def add_response(response) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
39
+ def add_response(response) # rubocop:disable Metrics/AbcSize
40
40
  request_id = response[:requestId]
41
41
  raise "ERROR" unless ongoing_request?(request_id)
42
42
 
data/lib/grumlin/step.rb CHANGED
@@ -14,7 +14,7 @@ module Grumlin
14
14
  @enum.next
15
15
  end
16
16
 
17
- def toList # rubocop:disable Naming/MethodName
17
+ def toList
18
18
  @pool.acquire do |client|
19
19
  client.write(*steps)
20
20
  end
data/lib/grumlin/sugar.rb CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Grumlin
4
4
  module Sugar
5
- # TODO: how to use it in specs?
6
5
  HELPERS = [
7
6
  Grumlin::U,
8
7
  Grumlin::T,
@@ -12,25 +11,12 @@ module Grumlin
12
11
  ].freeze
13
12
 
14
13
  def self.included(base)
15
- base.extend ClassMethods
16
- end
17
-
18
- module ClassMethods
19
- def const_missing(name)
20
- helper = HELPERS.find { |h| h.const_defined?(name) }
21
- super if helper.nil?
22
-
23
- const_set(name, helper)
14
+ HELPERS.each do |helper|
15
+ name = helper.name.split("::").last
16
+ base.const_set(name, helper)
24
17
  end
25
18
  end
26
19
 
27
- def const_missing(name)
28
- helper = HELPERS.find { |h| h.const_defined?(name) }
29
- super if helper.nil?
30
-
31
- const_set(name, helper)
32
- end
33
-
34
20
  def __
35
21
  Grumlin::U
36
22
  end
data/lib/grumlin/t.rb CHANGED
@@ -2,21 +2,16 @@
2
2
 
3
3
  module Grumlin
4
4
  module T
5
- module T
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?
5
+ # TODO: share the code?
6
+ class << self
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
- extend self # rubocop:disable Style/ModuleFunction
10
-
11
- def id
12
- T_ID
13
- end
14
-
15
- def label
16
- T_LABEL
12
+ instance_variable_set(name, TypedValue.new("T", step))
13
+ end
17
14
  end
18
15
  end
19
-
20
- extend T
21
16
  end
22
17
  end
@@ -8,8 +8,14 @@ module Grumlin
8
8
 
9
9
  ::RSpec.shared_context GremlinContext do
10
10
  include GremlinContext
11
+ include Grumlin::Sugar
11
12
 
12
- let(:g) { Grumlin::Traversal.new }
13
+ before do
14
+ Grumlin::Sugar::HELPERS.each do |helper|
15
+ name = helper.name.split("::").last
16
+ stub_const(name, helper)
17
+ end
18
+ end
13
19
 
14
20
  after do
15
21
  Grumlin.config.default_pool.close
@@ -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
@@ -20,7 +20,7 @@ module Grumlin
20
20
  @connected
21
21
  end
22
22
 
23
- def connect # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
23
+ def connect # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
24
24
  raise AlreadyConnectedError if connected?
25
25
 
26
26
  @connection = Async::WebSocket::Client.connect(Async::HTTP::Endpoint.parse(@url), **@client_options)
@@ -56,7 +56,7 @@ module Grumlin
56
56
  @request_channel << message
57
57
  end
58
58
 
59
- def close # rubocop:disable Metrics/MethodLength
59
+ def close
60
60
  return unless connected?
61
61
 
62
62
  @request_channel.close
@@ -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,17 +2,15 @@
2
2
 
3
3
  module Grumlin
4
4
  module U
5
- module U
6
- extend self # rubocop:disable Style/ModuleFunction
5
+ # TODO: add other start steps
6
+ SUPPORTED_START_STEPS = %w[V addV count has out unfold values].freeze
7
7
 
8
- %w[addV V has count out values unfold].each do |step|
8
+ class << self
9
+ SUPPORTED_START_STEPS.each do |step|
9
10
  define_method step do |*args|
10
11
  AnonymousStep.new(step, *args)
11
12
  end
12
13
  end
13
14
  end
14
-
15
- # TODO: add alias __
16
- extend U
17
15
  end
18
16
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Grumlin
4
- VERSION = "0.4.0"
4
+ VERSION = "0.6.1"
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"
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.4.0
4
+ version: 0.6.1
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-20 00:00:00.000000000 Z
11
+ date: 2021-09-01 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