Class: Mxrb::Dsl::FlowBuilder
- Inherits:
-
Object
- Object
- Mxrb::Dsl::FlowBuilder
show all
- Includes:
- FlowBodyDsl
- Defined in:
- lib/mxrb/dsl/builder.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#aggregate, #call_microflow, #call_rest, #cast, #change_list, #change_object, #change_variable, #close_page, #commit, #continue_loop, #create_list, #create_object, #create_variable, #decision, #delete, #end_flow, #error_event, #list_operation, #log_message, #loop_over, #retrieve_association, #retrieve_objects, #rollback, #show_message, #show_page, #type_decision, #validation_feedback, #while_loop
Constructor Details
#initialize(name, runtime:, kind:, public:) ⇒ FlowBuilder
Returns a new instance of FlowBuilder.
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
|
# File 'lib/mxrb/dsl/builder.rb', line 1412
def initialize(name, runtime:, kind:, public:)
@name = name.to_s
@runtime = runtime
@kind = kind
@public = public
@parameters = []
@return_type = nil
@doc = ""
@calls = []
@repositories = []
@allowed_roles = nil
@body = nil
@return_variable_name = nil
@return_expression = nil
@expected_body_fingerprint = nil
@allow_concurrent_execution = nil
@mark_as_used = nil
@excluded = nil
end
|
Class Method Details
.body_digest(body, return_expression) ⇒ Object
1479
1480
1481
1482
|
# File 'lib/mxrb/dsl/builder.rb', line 1479
def self.body_digest(body, return_expression)
payload = canonical_body_value([body, return_expression])
Digest::SHA256.hexdigest(JSON.generate(payload))
end
|
.canonical_body_value(value) ⇒ Object
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
|
# File 'lib/mxrb/dsl/builder.rb', line 1484
def self.canonical_body_value(value)
case value
when Hash
value.keys.sort_by(&:to_s).to_h do |key|
[key.to_s, canonical_body_value(value[key])]
end
when Array
value.map { canonical_body_value(_1) }
when Symbol
{ "__symbol__" => value.to_s }
else
value
end
end
|
Instance Method Details
#allow_concurrent_execution(value = true) ⇒ Object
1442
|
# File 'lib/mxrb/dsl/builder.rb', line 1442
def allow_concurrent_execution(value = true) = (@allow_concurrent_execution = !!value)
|
#allowed_roles(*roles) ⇒ Object
1446
1447
1448
|
# File 'lib/mxrb/dsl/builder.rb', line 1446
def allowed_roles(*roles)
@allowed_roles = roles.map(&:to_s)
end
|
#body_fingerprint(value) ⇒ Object
1475
1476
1477
|
# File 'lib/mxrb/dsl/builder.rb', line 1475
def body_fingerprint(value)
@expected_body_fingerprint = value.to_s
end
|
#bson_binary(base64, subtype: :generic) ⇒ Object
1436
1437
1438
|
# File 'lib/mxrb/dsl/builder.rb', line 1436
def bson_binary(base64, subtype: :generic)
BSON::Binary.new(Base64.strict_decode64(base64), subtype.to_sym)
end
|
#call(microflow: nil, nanoflow: nil) ⇒ Object
1450
1451
1452
1453
1454
|
# File 'lib/mxrb/dsl/builder.rb', line 1450
def call(microflow: nil, nanoflow: nil)
choices = { microflow: microflow, nanoflow: nanoflow }.compact
raise ArgumentError, "call requires exactly one target" unless choices.size == 1
@calls << { kind: choices.keys.first, name: choices.values.first.to_s }
end
|
#documentation(d) ⇒ Object
1441
|
# File 'lib/mxrb/dsl/builder.rb', line 1441
def documentation(d) = (@doc = d)
|
#excluded(value = true) ⇒ Object
1444
|
# File 'lib/mxrb/dsl/builder.rb', line 1444
def excluded(value = true) = (@excluded = !!value)
|
#mark_as_used(value = true) ⇒ Object
1443
|
# File 'lib/mxrb/dsl/builder.rb', line 1443
def mark_as_used(value = true) = (@mark_as_used = !!value)
|
#parameter(name, type:) ⇒ Object
1432
1433
1434
|
# File 'lib/mxrb/dsl/builder.rb', line 1432
def parameter(name, type:)
@parameters << { name: name.to_s, type: type.is_a?(Hash) ? type : type.to_s }
end
|
#rescue_all(&block) ⇒ Object
1460
1461
1462
1463
1464
|
# File 'lib/mxrb/dsl/builder.rb', line 1460
def rescue_all(&block)
rb = RescueBuilder.new
rb.instance_eval(&block) if block
_acts << { type: :rescue_all, activities: rb.activities }
end
|
#return_type(t) ⇒ Object
1440
|
# File 'lib/mxrb/dsl/builder.rb', line 1440
def return_type(t) = (@return_type = t.to_s)
|
#return_value(var) ⇒ Object
1466
1467
1468
1469
1470
1471
1472
1473
|
# File 'lib/mxrb/dsl/builder.rb', line 1466
def return_value(var)
if var.is_a?(Symbol)
@return_variable_name = var.to_s
@return_expression = "$#{var}"
else
@return_expression = var.to_s
end
end
|
#to_h ⇒ Object
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
|
# File 'lib/mxrb/dsl/builder.rb', line 1499
def to_h
current_fingerprint = self.class.body_digest(@body, @return_expression)
{
name: @name, runtime: @runtime, kind: @kind, public: @public,
parameters: @parameters, return_type: @return_type, documentation: @doc,
calls: @calls, repositories: @repositories, allowed_roles: @allowed_roles,
body: @body, return_variable_name: @return_variable_name,
return_expression: @return_expression,
allow_concurrent_execution: @allow_concurrent_execution,
mark_as_used: @mark_as_used, excluded: @excluded,
preserve_native_body: !@expected_body_fingerprint.nil? &&
@expected_body_fingerprint == current_fingerprint
}
end
|
#uses_repository(name) ⇒ Object
1456
1457
1458
|
# File 'lib/mxrb/dsl/builder.rb', line 1456
def uses_repository(name)
@repositories << name.to_s
end
|