-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflow.rb
More file actions
75 lines (62 loc) · 2.31 KB
/
Copy pathflow.rb
File metadata and controls
75 lines (62 loc) · 2.31 KB
1
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
# frozen_string_literal: true
class Flow < ApplicationRecord
VALIDATION_STATUS = {
unvalidated: 0,
valid: 1,
invalid: 2,
}.with_indifferent_access
DISABLED_REASON = {
_dummy: { db: 0, description: 'Dummy value' }, # temporary until the first real disabled reason gets introduced
}.with_indifferent_access
belongs_to :project, class_name: 'NamespaceProject'
belongs_to :flow_type
belongs_to :starting_node, class_name: 'NodeFunction', optional: true
enum :validation_status, VALIDATION_STATUS, prefix: :validation_status
enum :disabled_reason, DISABLED_REASON.transform_values { |v| v[:db] }, prefix: :disabled_reason
has_many :flow_settings, class_name: 'FlowSetting', inverse_of: :flow
has_many :node_functions, class_name: 'NodeFunction', inverse_of: :flow
has_many :execution_results, inverse_of: :flow
has_many :flow_data_type_links, inverse_of: :flow
has_many :referenced_data_types, through: :flow_data_type_links, source: :referenced_data_type
validates :validation_status,
presence: true,
inclusion: {
in: VALIDATION_STATUS.keys.map(&:to_s),
}
validates :disabled_reason,
inclusion: {
in: DISABLED_REASON.keys.map(&:to_s),
},
if: :disabled?
validates :name, presence: true,
allow_blank: false,
uniqueness: { case_sensitive: false, scope: :project_id }
scope :enabled, -> { where(disabled_reason: nil) }
scope :disabled, -> { where.not(disabled_reason: nil) }
def disabled?
disabled_reason.present?
end
def to_grpc
Tucana::Shared::ValidationFlow.new(
flow_id: id,
project_id: project.id,
project_slug: project.slug,
type: flow_type.identifier,
data_types: [], # TODO: when data types are creatable
disable_reason: disabled_reason,
settings: flow_settings.map(&:to_grpc),
starting_node_id: starting_node&.id,
node_functions: node_functions.map(&:to_grpc),
signature: flow_type.signature
)
end
def to_generation_grpc
Tucana::Shared::GenerationFlow.new(
name: name,
type: flow_type.identifier,
starting_node_id: starting_node&.id&.to_s,
settings: flow_settings.map(&:to_grpc),
node_functions: node_functions.map(&:to_grpc)
)
end
end