Module: Mxrb::Dsl::FlowBodyDsl

Included in:
BranchBuilder, FlowBuilder, LoopBuilder, RescueBuilder
Defined in:
lib/mxrb/dsl/builder.rb

Overview

Shared activity DSL mixed into FlowBuilder, BranchBuilder, LoopBuilder, RescueBuilder

Instance Method Summary collapse

Instance Method Details

#aggregate(list, function:, as:, attribute: nil) ⇒ Object



1410
1411
1412
1413
1414
1415
# File 'lib/mxrb/dsl/builder.rb', line 1410

def aggregate(list, function:, as:, attribute: nil)
  _acts << {
    type: :aggregate, variable: list.to_s, function: function.to_s,
    output: as.to_s, attribute: attribute.to_s
  }
end

#call_microflow(name, as: nil, pass: {}, result_name: nil, use_return: nil) ⇒ Object



1344
1345
1346
1347
1348
1349
1350
1351
1352
# File 'lib/mxrb/dsl/builder.rb', line 1344

def call_microflow(name, as: nil, pass: {}, result_name: nil, use_return: nil)
  mappings = pass.map { |param, var| { param: param.to_s, value: var } }
  _acts << {
    type: :call_microflow, name: name.to_s, variable: as&.to_s,
    result_name: result_name&.to_s,
    use_return: use_return.nil? ? !as.nil? : use_return == true,
    mappings: mappings
  }
end

#call_rest(method:, location:, location_parameters: [], headers: {}, request_mapping: nil, request_variable: nil, result_mapping: nil, as: nil, result_entity: nil, timeout: nil, commit: :yes_without_events, error_result: :http_response, error: :rollback) ⇒ Object



1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
# File 'lib/mxrb/dsl/builder.rb', line 1454

def call_rest(method:, location:, location_parameters: [], headers: {},
              request_mapping: nil, request_variable: nil,
              result_mapping: nil, as: nil, result_entity: nil,
              timeout: nil, commit: :yes_without_events,
              error_result: :http_response, error: :rollback)
  _acts << {
    type: :call_rest, method: method.to_s, location: location.to_s,
    location_parameters: Array(location_parameters),
    headers: headers.transform_keys(&:to_s),
    request_mapping: request_mapping&.to_s,
    request_variable: request_variable&.to_s,
    result_mapping: result_mapping&.to_s, variable: as&.to_s,
    result_entity: result_entity&.to_s, timeout: timeout&.to_s,
    commit: commit.to_s, error_result: error_result.to_s,
    error: error.to_s
  }
end

#cast(variable) ⇒ Object



1421
1422
1423
# File 'lib/mxrb/dsl/builder.rb', line 1421

def cast(variable)
  _acts << { type: :cast, variable: variable.to_s }
end

#change_list(list, action:, value:) ⇒ Object



1437
1438
1439
1440
1441
1442
# File 'lib/mxrb/dsl/builder.rb', line 1437

def change_list(list, action:, value:)
  _acts << {
    type: :change_list, variable: list.to_s,
    action: action.to_s, value: value
  }
end

#change_object(variable, set: {}, commit: false, with_events: true, refresh: false, &block) ⇒ Object



1313
1314
1315
1316
1317
1318
# File 'lib/mxrb/dsl/builder.rb', line 1313

def change_object(variable, set: {}, commit: false, with_events: true,
                  refresh: false, &block)
  _acts << { type: :change_object, variable: variable.to_s,
             members: _build_members(set, &block), commit: commit,
             with_events: with_events, refresh: refresh }
end

#change_variable(name, to:) ⇒ Object



1374
1375
1376
# File 'lib/mxrb/dsl/builder.rb', line 1374

def change_variable(name, to:)
  _acts << { type: :change_variable, variable: name.to_s, value: to }
end

#close_page(count: nil) ⇒ Object



1406
1407
1408
# File 'lib/mxrb/dsl/builder.rb', line 1406

def close_page(count: nil)
  _acts << { type: :close_page, count: count }
end

#commit(variable, with_events: true, refresh: false) ⇒ Object



1333
1334
1335
1336
1337
1338
# File 'lib/mxrb/dsl/builder.rb', line 1333

def commit(variable, with_events: true, refresh: false)
  _acts << {
    type: :commit, variable: variable.to_s,
    with_events: with_events, refresh: refresh
  }
end

#continue_loopObject



1485
1486
1487
# File 'lib/mxrb/dsl/builder.rb', line 1485

def continue_loop
  _acts << { type: :continue_event }
end

#create_list(entity, as:) ⇒ Object



1425
1426
1427
# File 'lib/mxrb/dsl/builder.rb', line 1425

def create_list(entity, as:)
  _acts << { type: :create_list, entity: entity.to_s, variable: as.to_s }
end

#create_object(entity, as:, set: {}, commit: false, with_events: true, refresh: false, &block) ⇒ Object



1306
1307
1308
1309
1310
1311
# File 'lib/mxrb/dsl/builder.rb', line 1306

def create_object(entity, as:, set: {}, commit: false, with_events: true,
                  refresh: false, &block)
  _acts << { type: :create_object, entity: entity.to_s, variable: as.to_s,
             members: _build_members(set, &block), commit: commit,
             with_events: with_events, refresh: refresh }
end

#create_variable(name, type: nil, value: nil) ⇒ Object



1367
1368
1369
1370
1371
1372
# File 'lib/mxrb/dsl/builder.rb', line 1367

def create_variable(name, type: nil, value: nil)
  _acts << {
    type: :create_variable, variable: name.to_s,
    variable_type: type&.to_s, value: value
  }
end

#decision(condition, &block) ⇒ Object



1498
1499
1500
1501
1502
# File 'lib/mxrb/dsl/builder.rb', line 1498

def decision(condition, &block)
  db = DecisionBuilder.new(condition.is_a?(Hash) ? condition : condition.to_s)
  db.instance_eval(&block) if block
  _acts << db.to_h
end

#delete(variable, refresh: false) ⇒ Object



1340
1341
1342
# File 'lib/mxrb/dsl/builder.rb', line 1340

def delete(variable, refresh: false)
  _acts << { type: :delete_object, variable: variable.to_s, refresh: refresh }
end

#end_flowObject



1477
1478
1479
# File 'lib/mxrb/dsl/builder.rb', line 1477

def end_flow
  _acts << { type: :return_event, expression: "" }
end

#error_eventObject



1481
1482
1483
# File 'lib/mxrb/dsl/builder.rb', line 1481

def error_event
  _acts << { type: :error_event }
end

#list_operation(operation, list, as:, with: nil, expression: nil) ⇒ Object



1429
1430
1431
1432
1433
1434
1435
# File 'lib/mxrb/dsl/builder.rb', line 1429

def list_operation(operation, list, as:, with: nil, expression: nil)
  _acts << {
    type: :list_operation, operation: operation.to_s,
    variable: list.to_s, second: with&.to_s,
    expression: expression&.to_s, output: as.to_s
  }
end

#log_message(message, level: :info, node: nil, include_stack: false, parameters: []) ⇒ Object



1388
1389
1390
1391
1392
1393
1394
# File 'lib/mxrb/dsl/builder.rb', line 1388

def log_message(message, level: :info, node: nil, include_stack: false, parameters: [])
  _acts << {
    type: :log_message, message: message.to_s, level: level.to_s,
    node: node&.to_s, include_stack: include_stack,
    parameters: Array(parameters)
  }
end

#loop_over(variable, as: nil, &block) ⇒ Object



1510
1511
1512
1513
1514
# File 'lib/mxrb/dsl/builder.rb', line 1510

def loop_over(variable, as: nil, &block)
  lb = LoopBuilder.new(variable.to_s, as: (as || variable).to_s)
  lb.instance_eval(&block) if block
  _acts << lb.to_h
end

#rescue_all(&block) ⇒ Object



1489
1490
1491
1492
1493
1494
1495
1496
# File 'lib/mxrb/dsl/builder.rb', line 1489

def rescue_all(&block)
  rescue_builder = RescueBuilder.new
  rescue_builder.instance_eval(&block) if block
  _acts << {
    type: :rescue_all,
    activities: rescue_builder.activities
  }
end

#retrieve_association(from, association:, as:) ⇒ Object



1326
1327
1328
1329
1330
1331
# File 'lib/mxrb/dsl/builder.rb', line 1326

def retrieve_association(from, association:, as:)
  _acts << {
    type: :retrieve_association, variable: as.to_s,
    start_variable: from.to_s, association: association.to_s
  }
end

#retrieve_objects(entity, as:, xpath: nil, limit: nil, single: false, sort: []) ⇒ Object



1320
1321
1322
1323
1324
# File 'lib/mxrb/dsl/builder.rb', line 1320

def retrieve_objects(entity, as:, xpath: nil, limit: nil, single: false, sort: [])
  _acts << { type: :retrieve_objects, entity: entity.to_s, variable: as.to_s,
             xpath: xpath&.to_s, limit: limit, single: single,
             sortings: Array(sort) }
end

#return_value(value) ⇒ Object



1472
1473
1474
1475
# File 'lib/mxrb/dsl/builder.rb', line 1472

def return_value(value)
  expression = value.is_a?(Symbol) ? "$#{value}" : value.to_s
  _acts << { type: :return_event, expression: expression }
end

#rollback(variable, refresh: false) ⇒ Object



1417
1418
1419
# File 'lib/mxrb/dsl/builder.rb', line 1417

def rollback(variable, refresh: false)
  _acts << { type: :rollback, variable: variable.to_s, refresh: refresh }
end

#show_message(text = nil, type: :information, blocking: false, translations: nil, parameters: []) ⇒ Object



1378
1379
1380
1381
1382
1383
1384
1385
1386
# File 'lib/mxrb/dsl/builder.rb', line 1378

def show_message(text = nil, type: :information, blocking: false,
                 translations: nil, parameters: [])
  _acts << {
    type: :show_message, text: text.to_s, message_type: type.to_s,
    blocking: blocking,
    translations: translations&.transform_keys(&:to_s),
    parameters: Array(parameters)
  }
end

#show_page(page, object: nil, location: nil, pass: {}, close_pages: nil, title: nil) ⇒ Object



1396
1397
1398
1399
1400
1401
1402
1403
1404
# File 'lib/mxrb/dsl/builder.rb', line 1396

def show_page(page, object: nil, location: nil, pass: {}, close_pages: nil,
              title: nil)
  _acts << {
    type: :show_page, page: page.to_s, variable: object&.to_s,
    location: location&.to_s,
    mappings: pass.map { |parameter, value| { parameter: parameter.to_s, value: value } },
    close_pages: close_pages, title: title
  }
end

#type_decision(variable, &block) ⇒ Object



1504
1505
1506
1507
1508
# File 'lib/mxrb/dsl/builder.rb', line 1504

def type_decision(variable, &block)
  builder = TypeDecisionBuilder.new(variable.to_s)
  builder.instance_eval(&block) if block
  _acts << builder.to_h
end

#validation_feedback(variable, attribute: nil, association: nil, translations: {}, parameters: [], error: :rollback) ⇒ Object



1444
1445
1446
1447
1448
1449
1450
1451
1452
# File 'lib/mxrb/dsl/builder.rb', line 1444

def validation_feedback(variable, attribute: nil, association: nil,
                        translations: {}, parameters: [], error: :rollback)
  _acts << {
    type: :validation_feedback, variable: variable.to_s,
    attribute: attribute.to_s, association: association.to_s,
    translations: translations.transform_keys(&:to_s),
    parameters: Array(parameters), error: error.to_s
  }
end

#while_loop(condition, &block) ⇒ Object



1516
1517
1518
1519
1520
1521
1522
1523
# File 'lib/mxrb/dsl/builder.rb', line 1516

def while_loop(condition, &block)
  lb = LoopBuilder.new(nil, as: nil)
  lb.instance_eval(&block) if block
  item = lb.to_h
  item[:type] = :while_loop
  item[:condition] = condition.to_s
  _acts << item
end