Skip to content

Commit 5e356dc

Browse files
Merge pull request #1160 from code0-tech/#1126-add-definition-source
add definition source
2 parents db59e74 + c49816f commit 5e356dc

13 files changed

Lines changed: 87 additions & 15 deletions

File tree

app/models/runtime_module.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class RuntimeModule < ApplicationRecord
2222
validates :documentation, length: { maximum: 200 }, exclusion: { in: [nil] }
2323
validates :author, length: { maximum: 200 }, exclusion: { in: [nil] }
2424
validates :icon, length: { maximum: 100 }
25+
validates :definition_source, length: { maximum: 50 }
2526

2627
validate :validate_version
2728

app/models/sub_flow.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@ def function_identifier
1414
end
1515

1616
def to_grpc
17-
Tucana::Shared::SubFlow.new(
17+
grpc_sub_flow = Tucana::Shared::SubFlow.new(
1818
starting_node_id: starting_node_id,
19-
function_identifier: function_identifier,
2019
signature: signature,
2120
settings: sub_flow_settings.map(&:to_grpc)
2221
)
22+
if function_definition.present?
23+
function_args = { function_identifier: function_identifier }
24+
definition_source = function_definition.runtime_function_definition.definition_source
25+
function_args[:definition_source] = definition_source if definition_source.present?
26+
27+
grpc_sub_flow.function = Tucana::Shared::SubFlow::SubFlowFunction.new(**function_args)
28+
end
29+
30+
grpc_sub_flow
2331
end
2432

2533
private

app/services/runtimes/grpc/modules/update_service.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def update_modules(t)
5757
module_record.author = grpc_module.author
5858
module_record.icon = grpc_module.icon
5959
module_record.version = grpc_module.version
60+
module_record.definition_source = grpc_module.definition_source
6061
module_record.names = update_translations(grpc_module.name, module_record.names)
6162
module_record.descriptions = update_translations(grpc_module.description, module_record.descriptions)
6263

app/services/velorum/generation_flow_serializer.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ def prepare_definition_ids
7575
runtime_name = if definition.respond_to?(:runtime_function_definition)
7676
definition.runtime_function_definition&.runtime_name
7777
end
78+
definition_source = definition.runtime_function_definition&.definition_source
7879
function_definitions_by_runtime_id[runtime_name] ||= definition if runtime_name.present?
80+
if definition_source.present?
81+
function_definitions_by_runtime_id[[definition.identifier, definition_source]] ||= definition
82+
function_definitions_by_runtime_id[[runtime_name, definition_source]] ||= definition if runtime_name.present?
83+
end
7984
end
8085
end
8186

@@ -176,11 +181,15 @@ def reference_path_to_h(path)
176181
end
177182

178183
def sub_flow_to_h(sub_flow)
179-
function_definition = function_definition_for_identifier(sub_flow.function_identifier)
180-
if runtime.present? && sub_flow.function_identifier.present? && function_definition.nil?
184+
sub_flow_function = sub_flow.function if sub_flow.execution_reference == :function
185+
function_identifier = sub_flow_function&.function_identifier
186+
definition_source = sub_flow_function.definition_source if sub_flow_function&.has_definition_source?
187+
function_definition = function_definition_for_identifier(function_identifier, definition_source)
188+
if runtime.present? && function_identifier.present? && function_definition.nil?
181189
raise_unresolved_definition(
182190
'Generated sub-flow function definition is unknown',
183-
function_identifier: sub_flow.function_identifier
191+
function_identifier: function_identifier,
192+
definition_source: definition_source
184193
)
185194
end
186195

@@ -251,7 +260,11 @@ def function_definition_for(node)
251260
function_definition_for_identifier(node.runtime_function_id)
252261
end
253262

254-
def function_definition_for_identifier(identifier)
263+
def function_definition_for_identifier(identifier, definition_source = nil)
264+
return if identifier.blank?
265+
266+
return function_definitions_by_runtime_id[[identifier, definition_source]] if definition_source.present?
267+
255268
function_definitions_by_runtime_id[identifier]
256269
end
257270

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class AddDefinitionSourceToRuntimeModules < Code0::ZeroTrack::Database::Migration[1.0]
4+
def change
5+
add_column :runtime_modules, :definition_source, :text, limit: 50
6+
end
7+
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
541adfd19676c98dbebc7109fbc7f86f0fda1e2243b8ecf40275d4b8efb271d5

db/structure.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,10 @@ CREATE TABLE runtime_modules (
956956
version text NOT NULL,
957957
created_at timestamp with time zone NOT NULL,
958958
updated_at timestamp with time zone NOT NULL,
959+
definition_source text,
959960
CONSTRAINT check_1a843f8ec6 CHECK ((char_length(identifier) <= 50)),
960961
CONSTRAINT check_3f8395fc6a CHECK ((char_length(icon) <= 100)),
962+
CONSTRAINT check_436ae79860 CHECK ((char_length(definition_source) <= 50)),
961963
CONSTRAINT check_59e12f7f02 CHECK ((char_length(author) <= 200)),
962964
CONSTRAINT check_d169c23c07 CHECK ((char_length(documentation) <= 200))
963965
);

spec/factories/runtime_modules.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
author { '' }
1111
icon { nil }
1212
version { '0.0.0' }
13+
definition_source { 'taurus' }
1314
end
1415
end

spec/models/runtime_module_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
it { is_expected.to validate_length_of(:documentation).is_at_most(200) }
2626
it { is_expected.to validate_length_of(:author).is_at_most(200) }
2727
it { is_expected.to validate_length_of(:icon).is_at_most(100) }
28+
it { is_expected.to validate_length_of(:definition_source).is_at_most(50) }
2829

2930
describe '#validate_version' do
3031
it 'adds an error if version is blank' do

spec/models/sub_flow_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,24 @@
2020
expect(sub_flow.errors[:base]).to include('Exactly one of starting_node or function_definition must be present')
2121
end
2222
end
23+
24+
describe '#to_grpc' do
25+
it 'serializes a function reference with its definition source' do
26+
runtime_function_definition = create(:runtime_function_definition, definition_source: 'taurus')
27+
function_definition = create(
28+
:function_definition,
29+
runtime: runtime_function_definition.runtime,
30+
runtime_function_definition: runtime_function_definition
31+
)
32+
sub_flow = create(:sub_flow, starting_node: nil, function_definition: function_definition)
33+
34+
grpc_sub_flow = sub_flow.to_grpc
35+
36+
expect(grpc_sub_flow.function).to have_attributes(
37+
function_identifier: function_definition.identifier,
38+
definition_source: 'taurus'
39+
)
40+
expect(grpc_sub_flow.function.has_definition_source?).to be(true)
41+
end
42+
end
2343
end

0 commit comments

Comments
 (0)