grumlin 0.23.0 → 1.0.0.rc2
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 +4 -4
- data/.rubocop.yml +9 -9
- data/Gemfile.lock +1 -1
- data/README.md +100 -142
- data/Rakefile +1 -1
- data/bin/console +18 -3
- data/doc/middlewares.md +49 -10
- data/lib/async/channel.rb +54 -56
- data/lib/grumlin/benchmark/repository.rb +10 -14
- data/lib/grumlin/client.rb +93 -95
- data/lib/grumlin/config.rb +33 -33
- data/lib/grumlin/dummy_transaction.rb +13 -15
- data/lib/grumlin/edge.rb +18 -20
- data/lib/grumlin/expressions/cardinality.rb +5 -9
- data/lib/grumlin/expressions/column.rb +5 -9
- data/lib/grumlin/expressions/expression.rb +7 -11
- data/lib/grumlin/expressions/operator.rb +5 -9
- data/lib/grumlin/expressions/order.rb +5 -9
- data/lib/grumlin/expressions/p.rb +27 -31
- data/lib/grumlin/expressions/pop.rb +5 -9
- data/lib/grumlin/expressions/scope.rb +5 -9
- data/lib/grumlin/expressions/t.rb +5 -9
- data/lib/grumlin/expressions/text_p.rb +5 -9
- data/lib/grumlin/expressions/with_options.rb +17 -21
- data/lib/grumlin/features/feature_list.rb +8 -12
- data/lib/grumlin/features/neptune_features.rb +5 -9
- data/lib/grumlin/features/tinkergraph_features.rb +5 -9
- data/lib/grumlin/features.rb +8 -10
- data/lib/grumlin/middlewares/apply_shortcuts.rb +4 -8
- data/lib/grumlin/middlewares/build_query.rb +16 -20
- data/lib/grumlin/middlewares/builder.rb +15 -0
- data/lib/grumlin/middlewares/cast_results.rb +3 -7
- data/lib/grumlin/middlewares/find_blocklisted_steps.rb +14 -0
- data/lib/grumlin/middlewares/find_mutating_steps.rb +9 -0
- data/lib/grumlin/middlewares/middleware.rb +6 -10
- data/lib/grumlin/middlewares/run_query.rb +3 -7
- data/lib/grumlin/middlewares/serialize_to_bytecode.rb +5 -9
- data/lib/grumlin/middlewares/serialize_to_steps.rb +4 -8
- data/lib/grumlin/path.rb +11 -13
- data/lib/grumlin/property.rb +14 -16
- data/lib/grumlin/query_validators/blocklisted_steps_validator.rb +22 -0
- data/lib/grumlin/query_validators/validator.rb +36 -0
- data/lib/grumlin/repository/error_handling_strategy.rb +36 -40
- data/lib/grumlin/repository/instance_methods.rb +115 -118
- data/lib/grumlin/repository.rb +82 -58
- data/lib/grumlin/request_dispatcher.rb +55 -57
- data/lib/grumlin/request_error_factory.rb +53 -55
- data/lib/grumlin/shortcut.rb +19 -21
- data/lib/grumlin/shortcuts/properties.rb +12 -16
- data/lib/grumlin/shortcuts/storage.rb +67 -74
- data/lib/grumlin/shortcuts/upserts.rb +19 -22
- data/lib/grumlin/shortcuts.rb +23 -25
- data/lib/grumlin/shortcuts_applyer.rb +27 -29
- data/lib/grumlin/step.rb +88 -90
- data/lib/grumlin/step_data.rb +12 -14
- data/lib/grumlin/steppable.rb +23 -25
- data/lib/grumlin/steps.rb +52 -54
- data/lib/grumlin/steps_serializers/bytecode.rb +53 -56
- data/lib/grumlin/steps_serializers/human_readable_bytecode.rb +17 -21
- data/lib/grumlin/steps_serializers/serializer.rb +7 -11
- data/lib/grumlin/steps_serializers/string.rb +26 -30
- data/lib/grumlin/test/rspec/db_cleaner_context.rb +8 -12
- data/lib/grumlin/test/rspec/gremlin_context.rb +18 -16
- data/lib/grumlin/test/rspec.rb +1 -5
- data/lib/grumlin/transaction.rb +34 -36
- data/lib/grumlin/transport.rb +71 -73
- data/lib/grumlin/traversal_start.rb +31 -33
- data/lib/grumlin/traversal_strategies/options_strategy.rb +3 -7
- data/lib/grumlin/traverser.rb +5 -7
- data/lib/grumlin/typed_value.rb +11 -13
- data/lib/grumlin/typing.rb +70 -72
- data/lib/grumlin/version.rb +1 -1
- data/lib/grumlin/vertex.rb +14 -16
- data/lib/grumlin/vertex_property.rb +14 -16
- data/lib/grumlin/with_extension.rb +17 -19
- data/lib/grumlin.rb +13 -0
- metadata +9 -6
- data/lib/grumlin/middlewares/frozen_builder.rb +0 -18
- data/lib/grumlin/sugar.rb +0 -15
data/lib/grumlin/step.rb
CHANGED
@@ -1,94 +1,92 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
pool: @pool)
|
92
|
-
end
|
3
|
+
class Grumlin::Step < Grumlin::Steppable
|
4
|
+
attr_reader :name, :args, :params, :next_step, :configuration_steps, :previous_step, :shortcut
|
5
|
+
|
6
|
+
# TODO: replace pool, session_id and middlewares with a context?
|
7
|
+
def initialize(name, args: [], params: {}, previous_step: nil, pool: nil, session_id: nil, # rubocop:disable Metrics/ParameterLists
|
8
|
+
middlewares: Grumlin.default_middlewares)
|
9
|
+
super(pool: pool, session_id: session_id, middlewares: middlewares)
|
10
|
+
|
11
|
+
@name = name.to_sym
|
12
|
+
@args = args # TODO: add recursive validation: only json types or Step
|
13
|
+
@params = params # TODO: add recursive validation: only json types
|
14
|
+
@previous_step = previous_step
|
15
|
+
@shortcut = shortcuts[@name]
|
16
|
+
end
|
17
|
+
|
18
|
+
def configuration_step?
|
19
|
+
CONFIGURATION_STEPS.include?(@name) || name.to_sym == :tx
|
20
|
+
end
|
21
|
+
|
22
|
+
def start_step?
|
23
|
+
START_STEPS.include?(@name)
|
24
|
+
end
|
25
|
+
|
26
|
+
def regular_step?
|
27
|
+
REGULAR_STEPS.include?(@name)
|
28
|
+
end
|
29
|
+
|
30
|
+
def supported_step?
|
31
|
+
ALL_STEPS.include?(@name)
|
32
|
+
end
|
33
|
+
|
34
|
+
def ==(other)
|
35
|
+
self.class == other.class &&
|
36
|
+
@name == other.name &&
|
37
|
+
@args == other.args &&
|
38
|
+
@params == other.params &&
|
39
|
+
@previous_step == other.previous_step &&
|
40
|
+
shortcuts == other.shortcuts
|
41
|
+
end
|
42
|
+
|
43
|
+
def steps
|
44
|
+
@steps ||= Grumlin::Steps.from(self)
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_s(**params)
|
48
|
+
Grumlin::StepsSerializers::String.new(steps, **params).serialize
|
49
|
+
end
|
50
|
+
|
51
|
+
# TODO: add human readable mode
|
52
|
+
def inspect
|
53
|
+
conf_steps, regular_steps = Grumlin::StepsSerializers::HumanReadableBytecode.new(steps).serialize
|
54
|
+
"#{conf_steps.any? ? conf_steps : nil}#{regular_steps}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def bytecode(no_return: false)
|
58
|
+
Grumlin::StepsSerializers::Bytecode.new(steps, no_return: no_return)
|
59
|
+
end
|
60
|
+
|
61
|
+
def next
|
62
|
+
to_enum.next
|
63
|
+
end
|
64
|
+
|
65
|
+
def hasNext # rubocop:disable Naming/MethodName
|
66
|
+
to_enum.peek
|
67
|
+
true
|
68
|
+
rescue StopIteration
|
69
|
+
false
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_enum
|
73
|
+
@to_enum ||= toList.to_enum
|
74
|
+
end
|
75
|
+
|
76
|
+
def toList
|
77
|
+
send_query(need_results: true)
|
78
|
+
end
|
79
|
+
|
80
|
+
def iterate
|
81
|
+
send_query(need_results: false)
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def send_query(need_results:)
|
87
|
+
@middlewares.call(traversal: self,
|
88
|
+
need_results: need_results,
|
89
|
+
session_id: @session_id,
|
90
|
+
pool: @pool)
|
93
91
|
end
|
94
92
|
end
|
data/lib/grumlin/step_data.rb
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
attr_reader :name, :args, :params
|
3
|
+
class Grumlin::StepData
|
4
|
+
attr_reader :name, :args, :params
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
def initialize(name, args: [], params: {})
|
7
|
+
@name = name
|
8
|
+
@args = args
|
9
|
+
@params = params
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
12
|
+
def ==(other)
|
13
|
+
self.class == other.class &&
|
14
|
+
@name == other.name &&
|
15
|
+
@args == other.args &&
|
16
|
+
@params == other.params
|
19
17
|
end
|
20
18
|
end
|
data/lib/grumlin/steppable.rb
CHANGED
@@ -1,40 +1,38 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
extend Forwardable
|
3
|
+
class Grumlin::Steppable
|
4
|
+
extend Forwardable
|
6
5
|
|
7
|
-
|
6
|
+
attr_reader :session_id
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
START_STEPS = Grumlin.definitions.dig(:steps, :start).map(&:to_sym).freeze
|
9
|
+
REGULAR_STEPS = Grumlin.definitions.dig(:steps, :regular).map(&:to_sym).freeze
|
10
|
+
CONFIGURATION_STEPS = Grumlin.definitions.dig(:steps, :configuration).map(&:to_sym).freeze
|
12
11
|
|
13
|
-
|
12
|
+
ALL_STEPS = START_STEPS + CONFIGURATION_STEPS + REGULAR_STEPS
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def initialize(pool: nil, session_id: nil, middlewares: Grumlin.default_middlewares)
|
15
|
+
@pool = pool
|
16
|
+
@session_id = session_id
|
18
17
|
|
19
|
-
|
18
|
+
@middlewares = middlewares
|
20
19
|
|
21
|
-
|
20
|
+
return if respond_to?(:shortcuts)
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
ALL_STEPS.each do |step|
|
27
|
-
define_method step do |*args, **params|
|
28
|
-
shortcuts.step_class.new(step, args: args, params: params, previous_step: self,
|
29
|
-
session_id: @session_id, pool: @pool, middlewares: @middlewares)
|
30
|
-
end
|
31
|
-
end
|
22
|
+
raise "steppable must not be initialized directly, use Grumlin::Shortcuts::Storage#g or #__ instead"
|
23
|
+
end
|
32
24
|
|
33
|
-
|
34
|
-
|
25
|
+
ALL_STEPS.each do |step|
|
26
|
+
define_method step do |*args, **params|
|
27
|
+
shortcuts.step_class.new(step, args: args, params: params, previous_step: self,
|
35
28
|
session_id: @session_id, pool: @pool, middlewares: @middlewares)
|
36
29
|
end
|
30
|
+
end
|
37
31
|
|
38
|
-
|
32
|
+
def step(name, *args, **params)
|
33
|
+
shortcuts.step_class.new(name, args: args, params: params, previous_step: self,
|
34
|
+
session_id: @session_id, pool: @pool, middlewares: @middlewares)
|
39
35
|
end
|
36
|
+
|
37
|
+
def_delegator :shortcuts, :__
|
40
38
|
end
|
data/lib/grumlin/steps.rb
CHANGED
@@ -1,78 +1,76 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
ALL_STEPS = Step::ALL_STEPS
|
7
|
-
|
8
|
-
def self.from(step)
|
9
|
-
raise ArgumentError, "expected: #{Step}, given: #{step.class}" unless step.is_a?(Step)
|
10
|
-
|
11
|
-
new(step.shortcuts).tap do |chain|
|
12
|
-
until step.nil? || step.is_a?(TraversalStart)
|
13
|
-
chain.add(step.name, args: step.args, params: step.params, to: :begin)
|
14
|
-
step = step.previous_step
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
3
|
+
class Grumlin::Steps
|
4
|
+
CONFIGURATION_STEPS = Grumlin::Step::CONFIGURATION_STEPS
|
5
|
+
ALL_STEPS = Grumlin::Step::ALL_STEPS
|
18
6
|
|
19
|
-
|
7
|
+
def self.from(step)
|
8
|
+
raise ArgumentError, "expected: #{Grumlin::Step}, given: #{step.class}" unless step.is_a?(Grumlin::Step)
|
20
9
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
10
|
+
new(step.shortcuts).tap do |chain|
|
11
|
+
until step.nil? || step.is_a?(Grumlin::TraversalStart)
|
12
|
+
chain.add(step.name, args: step.args, params: step.params, to: :begin)
|
13
|
+
step = step.previous_step
|
14
|
+
end
|
25
15
|
end
|
16
|
+
end
|
26
17
|
|
27
|
-
|
28
|
-
if CONFIGURATION_STEPS.include?(name) || name.to_sym == :tx
|
29
|
-
return add_configuration_step(name, args: args, params: params, to: to)
|
30
|
-
end
|
18
|
+
attr_reader :configuration_steps, :steps, :shortcuts
|
31
19
|
|
32
|
-
|
33
|
-
|
34
|
-
|
20
|
+
def initialize(shortcuts, configuration_steps: [], steps: [])
|
21
|
+
@shortcuts = shortcuts
|
22
|
+
@configuration_steps = configuration_steps
|
23
|
+
@steps = steps
|
24
|
+
end
|
35
25
|
|
36
|
-
|
37
|
-
|
26
|
+
def add(name, args: [], params: {}, to: :end)
|
27
|
+
if CONFIGURATION_STEPS.include?(name) || name.to_sym == :tx
|
28
|
+
return add_configuration_step(name, args: args, params: params, to: to)
|
38
29
|
end
|
39
30
|
|
40
|
-
|
41
|
-
|
42
|
-
|
31
|
+
Grumlin::StepData.new(name, args: cast_arguments(args), params: params).tap do |step|
|
32
|
+
next @steps << step if to == :end
|
33
|
+
next @steps.unshift(step) if to == :begin
|
43
34
|
|
44
|
-
|
45
|
-
self.class == other.class &&
|
46
|
-
@shortcuts == other.shortcuts &&
|
47
|
-
@configuration_steps == other.configuration_steps &&
|
48
|
-
@steps == other.steps
|
35
|
+
raise ArgumentError, "'to:' must be either :begin or :end, given: '#{to}'"
|
49
36
|
end
|
37
|
+
end
|
50
38
|
|
51
|
-
|
39
|
+
def uses_shortcuts?
|
40
|
+
shortcuts?(@configuration_steps) || shortcuts?(@steps)
|
41
|
+
end
|
42
|
+
|
43
|
+
def ==(other)
|
44
|
+
self.class == other.class &&
|
45
|
+
@shortcuts == other.shortcuts &&
|
46
|
+
@configuration_steps == other.configuration_steps &&
|
47
|
+
@steps == other.steps
|
48
|
+
end
|
49
|
+
|
50
|
+
# TODO: add #bytecode, to_s, inspect
|
52
51
|
|
53
|
-
|
52
|
+
private
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
54
|
+
def shortcuts?(steps_ary)
|
55
|
+
steps_ary.any? do |step|
|
56
|
+
@shortcuts.known?(step.name) || step.args.any? do |arg|
|
57
|
+
arg.is_a?(Grumlin::Steps) ? arg.uses_shortcuts? : false
|
60
58
|
end
|
61
59
|
end
|
60
|
+
end
|
62
61
|
|
63
|
-
|
64
|
-
|
62
|
+
def add_configuration_step(name, args: [], params: {}, to: :end)
|
63
|
+
raise ArgumentError, "cannot use configuration steps after start step was used" if @steps.any? && to == :end
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
Grumlin::StepData.new(name, args: cast_arguments(args), params: params).tap do |step|
|
66
|
+
next @configuration_steps << step if to == :end
|
67
|
+
next @configuration_steps.unshift(step) if to == :begin
|
69
68
|
|
70
|
-
|
71
|
-
end
|
69
|
+
raise ArgumentError, "to must be either :begin or :end, given: '#{to}'"
|
72
70
|
end
|
71
|
+
end
|
73
72
|
|
74
|
-
|
75
|
-
|
76
|
-
end
|
73
|
+
def cast_arguments(arguments)
|
74
|
+
arguments.map { |arg| arg.is_a?(Grumlin::Step) ? Grumlin::Steps.from(arg) : arg }
|
77
75
|
end
|
78
76
|
end
|
@@ -1,72 +1,69 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# constructor params: no_return: true|false, default false
|
7
|
-
# TODO: add pretty
|
3
|
+
class Grumlin::StepsSerializers::Bytecode < Grumlin::StepsSerializers::Serializer
|
4
|
+
# constructor params: no_return: true|false, default false
|
5
|
+
# TODO: add pretty
|
8
6
|
|
9
|
-
|
7
|
+
NONE_STEP = Grumlin::StepData.new("none")
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
def serialize
|
10
|
+
steps = Grumlin::ShortcutsApplyer.call(@steps)
|
11
|
+
no_return = @params.fetch(:no_return, false)
|
12
|
+
{}.tap do |result|
|
13
|
+
result[:step] = serialize_steps(steps.steps + (no_return ? [NONE_STEP] : [])) if steps.steps.any?
|
14
|
+
result[:source] = serialize_steps(steps.configuration_steps) if steps.configuration_steps.any?
|
15
|
+
end
|
16
|
+
end
|
19
17
|
|
20
|
-
|
18
|
+
private
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
def serialize_steps(steps)
|
21
|
+
steps.map { |s| serialize_step(s) }
|
22
|
+
end
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
result << step.params if step.params.any?
|
32
|
-
end
|
24
|
+
def serialize_step(step)
|
25
|
+
[step.name].tap do |result|
|
26
|
+
step.args.each do |arg|
|
27
|
+
result << serialize_arg(arg)
|
33
28
|
end
|
29
|
+
result << step.params if step.params.any?
|
30
|
+
end
|
31
|
+
end
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
def serialize_arg(arg)
|
34
|
+
return serialize_typed_value(arg) if arg.is_a?(Grumlin::TypedValue)
|
35
|
+
return serialize_predicate(arg) if arg.is_a?(Grumlin::Expressions::P::Predicate)
|
36
|
+
return arg.value if arg.is_a?(Grumlin::Expressions::WithOptions)
|
39
37
|
|
40
|
-
|
38
|
+
return arg unless arg.is_a?(Grumlin::Steps)
|
41
39
|
|
42
|
-
|
43
|
-
|
40
|
+
{ :@type => "g:Bytecode",
|
41
|
+
:@value => Grumlin::StepsSerializers::Bytecode.new(arg, **@params.merge(no_return: false)).serialize }
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
44
|
+
def serialize_typed_value(value)
|
45
|
+
return value.value if value.type.nil?
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
{
|
48
|
+
"@type": "g:#{value.type}",
|
49
|
+
"@value": value.value
|
50
|
+
}
|
51
|
+
end
|
53
52
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
70
|
-
end
|
53
|
+
def serialize_predicate(value)
|
54
|
+
{
|
55
|
+
"@type": "g:#{value.namespace}",
|
56
|
+
"@value": {
|
57
|
+
predicate: value.name,
|
58
|
+
value: if value.type.nil?
|
59
|
+
value.value
|
60
|
+
else
|
61
|
+
{
|
62
|
+
"@type": "g:#{value.type}",
|
63
|
+
"@value": value.value
|
64
|
+
}
|
65
|
+
end
|
66
|
+
}
|
67
|
+
}
|
71
68
|
end
|
72
69
|
end
|
@@ -1,30 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
end
|
3
|
+
class Grumlin::StepsSerializers::HumanReadableBytecode < Grumlin::StepsSerializers::Bytecode
|
4
|
+
def serialize
|
5
|
+
steps = Grumlin::ShortcutsApplyer.call(@steps)
|
6
|
+
[steps.configuration_steps, steps.steps].map do |stps|
|
7
|
+
stps.map { |s| serialize_step(s) }
|
8
|
+
end
|
9
|
+
end
|
12
10
|
|
13
|
-
|
11
|
+
private
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
def serialize_arg(arg)
|
14
|
+
return arg.to_s if arg.is_a?(Grumlin::TypedValue)
|
15
|
+
return serialize_predicate(arg) if arg.is_a?(Grumlin::Expressions::P::Predicate)
|
16
|
+
return arg.value if arg.is_a?(Grumlin::Expressions::WithOptions)
|
19
17
|
|
20
|
-
|
18
|
+
return arg unless arg.is_a?(Grumlin::Steps)
|
21
19
|
|
22
|
-
|
23
|
-
|
20
|
+
Grumlin::StepsSerializers::HumanReadableBytecode.new(arg, **@params.merge(no_return: false)).serialize[1]
|
21
|
+
end
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
23
|
+
def serialize_predicate(arg)
|
24
|
+
"#{arg.name}(#{arg.value})"
|
29
25
|
end
|
30
26
|
end
|
@@ -1,16 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@params = params
|
9
|
-
end
|
3
|
+
class Grumlin::StepsSerializers::Serializer
|
4
|
+
def initialize(steps, **params)
|
5
|
+
@steps = steps
|
6
|
+
@params = params
|
7
|
+
end
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
9
|
+
def serialize
|
10
|
+
raise NotImplementedError
|
15
11
|
end
|
16
12
|
end
|