Class: Mxrb::Dsl::FlowBuilder

Inherits:
Object
  • Object
show all
Includes:
FlowBodyDsl
Defined in:
lib/mxrb/dsl/builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FlowBodyDsl

#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.



1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
# File 'lib/mxrb/dsl/builder.rb', line 1541

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
  @apply_entity_access = nil
  @mark_as_used = nil
  @excluded = nil
end

Class Method Details

.body_digest(body, return_expression) ⇒ Object



1610
1611
1612
1613
# File 'lib/mxrb/dsl/builder.rb', line 1610

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



1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
# File 'lib/mxrb/dsl/builder.rb', line 1615

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



1572
# File 'lib/mxrb/dsl/builder.rb', line 1572

def allow_concurrent_execution(value = true) = (@allow_concurrent_execution = !!value)

#allowed_roles(*roles) ⇒ Object



1577
1578
1579
# File 'lib/mxrb/dsl/builder.rb', line 1577

def allowed_roles(*roles)
  @allowed_roles = roles.map(&:to_s)
end

#apply_entity_access(value = true) ⇒ Object



1573
# File 'lib/mxrb/dsl/builder.rb', line 1573

def apply_entity_access(value = true) = (@apply_entity_access = !!value)

#body_fingerprint(value) ⇒ Object



1606
1607
1608
# File 'lib/mxrb/dsl/builder.rb', line 1606

def body_fingerprint(value)
  @expected_body_fingerprint = value.to_s
end

#bson_binary(base64, subtype: :generic) ⇒ Object



1566
1567
1568
# File 'lib/mxrb/dsl/builder.rb', line 1566

def bson_binary(base64, subtype: :generic)
  BSON::Binary.new(Base64.strict_decode64(base64), subtype.to_sym)
end

#call(microflow: nil, nanoflow: nil) ⇒ Object

Raises:

  • (ArgumentError)


1581
1582
1583
1584
1585
# File 'lib/mxrb/dsl/builder.rb', line 1581

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



1571
# File 'lib/mxrb/dsl/builder.rb', line 1571

def documentation(d) = (@doc = d)

#excluded(value = true) ⇒ Object



1575
# File 'lib/mxrb/dsl/builder.rb', line 1575

def excluded(value = true) = (@excluded = !!value)

#mark_as_used(value = true) ⇒ Object



1574
# File 'lib/mxrb/dsl/builder.rb', line 1574

def mark_as_used(value = true) = (@mark_as_used = !!value)

#parameter(name, type:) ⇒ Object



1562
1563
1564
# File 'lib/mxrb/dsl/builder.rb', line 1562

def parameter(name, type:)
  @parameters << { name: name.to_s, type: type.is_a?(Hash) ? type : type.to_s }
end

#rescue_all(&block) ⇒ Object



1591
1592
1593
1594
1595
# File 'lib/mxrb/dsl/builder.rb', line 1591

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



1570
# File 'lib/mxrb/dsl/builder.rb', line 1570

def return_type(t) = (@return_type = t.to_s)

#return_value(var) ⇒ Object



1597
1598
1599
1600
1601
1602
1603
1604
# File 'lib/mxrb/dsl/builder.rb', line 1597

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_hObject



1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
# File 'lib/mxrb/dsl/builder.rb', line 1630

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,
    apply_entity_access: @apply_entity_access,
    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



1587
1588
1589
# File 'lib/mxrb/dsl/builder.rb', line 1587

def uses_repository(name)
  @repositories << name.to_s
end