grumlin 0.5.1 → 0.6.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: 5fb5b809483aeed3b56aeafc11e0f08919a68ce420a14ae918e3aecab791e266
4
- data.tar.gz: e42c886a034faeb5ca512882811e78a39f1f5f386b697b0f4061c5be5d5a5f0b
3
+ metadata.gz: a847514be85565126dc453b6f088ad5c9a388464e74f6744e34427f09a07ec9c
4
+ data.tar.gz: ea6b1241c611222aa7866b8c3a7b4b798d5a68ba09f79f030196758d4f2dd7f0
5
5
  SHA512:
6
- metadata.gz: 2bd8e23cd4e6ab7526e2e4aaf92dddfa2b1e0dc51fd2e15e9e0a09541e9716c741673a8e6f85b077e5fd1a3a5f16519ae533748347b1aff0ba5de47a8394ed47
7
- data.tar.gz: 673985aeb319810c061234e1d0964cf6e40b95363288423d7cda4e0932a7e271d51b957dccc5605a160e54e680d2a869bfa32769b393d19387e61e0ad15b7794
6
+ metadata.gz: 2aa5546c4b0139b1fd81cf2c2d5b32886a0c54ee958ddf3d9684ff9a38a19c8401fb2ef89a6767840f2dc0a12fbc86ea0b4821477f0721d767fc4c4f3a6cd7c1
7
+ data.tar.gz: 38da748bde5febd21a8d94a8ae00768fa8b25bb544dd9b9895a9dd544136faa489a8591d01386afcbb8ed103e5f909c7c4dfff2af9a69f2c42a77fa963be7438
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.1)
4
+ grumlin (0.6.0)
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
+ 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
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": "asc" }.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.1"
4
+ VERSION = "0.6.0"
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.5.1
4
+ version: 0.6.0
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-08-30 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