Class: Mxrb::Runtime::Native::Interpreter

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/runtime/native.rb

Overview

Executes the graph and core data activities directly from the MPR.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, store: nil, adapters: {}, java_custom_actions: {}, http: nil, policy: nil) ⇒ Interpreter

Returns a new instance of Interpreter.



503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
# File 'lib/mxrb/runtime/native.rb', line 503

def initialize(project, store: nil, adapters: {}, java_custom_actions: {}, http: nil, policy: nil)
  @project = project
  @expression = Expression.new
  @log = []
  @effects = []
  @call_depth = 0
  @call_monitor = Monitor.new
  @collection_plans = {
    true => {}.compare_by_identity,
    false => {}.compare_by_identity
  }
  @identifier_cache = {}.compare_by_identity
  @flow_case_cache = {}.compare_by_identity
  @adapters = adapters.transform_keys(&:to_sym)
  @java_custom_actions = java_custom_actions.to_h.transform_keys(&:to_s).freeze
  @java_action_parameter_names = {}
  @http = http || method(:http_request)
  @policy = policy
  @security_context = nil
  @apply_entity_access = false
  @flows = project.modules.flat_map do |mod|
    mod.microflows.map { ["#{mod.name}.#{_1.name}", _1] }
  end.to_h
  entity_names = project.modules.flat_map do |mod|
    mod.entities.map { [_1.id.to_s, "#{mod.name}.#{_1.name}"] }
  end.to_h
  defaults = project.modules.flat_map do |mod|
    mod.entities.map do |entity|
      ["#{mod.name}.#{entity.name}", entity.attributes.to_h do |attribute|
        [attribute.name, attribute_default(attribute)]
      end]
    end
  end.to_h
  transient_entities = project.modules.flat_map do |mod|
    mod.entities.select { _1.persistable == false }.map { "#{mod.name}.#{_1.name}" }
  end
  @store = store || Store.new(defaults:, transient_entities:)
  register_model_lifecycle
  @associations = project.modules.flat_map do |mod|
    mod.associations.map do |association|
      ["#{mod.name}.#{association.name}", {
        type: association.association_type,
        from: entity_names[association.from_entity_id.to_s]
      }]
    end
  end.to_h
end

Instance Attribute Details

#effectsObject (readonly)

Returns the value of attribute effects.



501
502
503
# File 'lib/mxrb/runtime/native.rb', line 501

def effects
  @effects
end

#logObject (readonly)

Returns the value of attribute log.



501
502
503
# File 'lib/mxrb/runtime/native.rb', line 501

def log
  @log
end

#storeObject (readonly)

Returns the value of attribute store.



501
502
503
# File 'lib/mxrb/runtime/native.rb', line 501

def store
  @store
end

Instance Method Details

#call(name, arguments = nil, context: nil, **keyword_arguments) ⇒ Object



551
552
553
554
555
# File 'lib/mxrb/runtime/native.rb', line 551

def call(name, arguments = nil, context: nil, **keyword_arguments)
  (@call_monitor ||= Monitor.new).synchronize do
    execute_call(name, arguments, context:, **keyword_arguments)
  end
end

#clear_effects!Object



557
# File 'lib/mxrb/runtime/native.rb', line 557

def clear_effects! = @effects.clear

#count(entity, xpath = nil) ⇒ Object

Counts stored objects of an entity, optionally narrowed by an XPath constraint. Used by the functional Executor's count expectations.



561
562
563
# File 'lib/mxrb/runtime/native.rb', line 561

def count(entity, xpath = nil)
  filter_by_xpath(store.retrieve(entity.to_s), xpath.to_s, {}).size
end