Class: Mxrb::Runtime::Native::Interpreter
- Inherits:
-
Object
- Object
- Mxrb::Runtime::Native::Interpreter
- Defined in:
- lib/mxrb/runtime/native.rb
Overview
Executes the graph and core data activities directly from the MPR.
Instance Attribute Summary collapse
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #call(name, arguments = {}) ⇒ Object
-
#count(entity, xpath = nil) ⇒ Object
Counts stored objects of an entity, optionally narrowed by an XPath constraint.
-
#initialize(project, store: Store.new) ⇒ Interpreter
constructor
A new instance of Interpreter.
Constructor Details
#initialize(project, store: Store.new) ⇒ Interpreter
Returns a new instance of Interpreter.
157 158 159 160 161 162 163 164 165 |
# File 'lib/mxrb/runtime/native.rb', line 157 def initialize(project, store: Store.new) @project = project @store = store @expression = Expression.new @log = [] @flows = project.modules.flat_map do |mod| mod.microflows.map { ["#{mod.name}.#{_1.name}", _1] } end.to_h end |
Instance Attribute Details
#log ⇒ Object (readonly)
Returns the value of attribute log.
155 156 157 |
# File 'lib/mxrb/runtime/native.rb', line 155 def log @log end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
155 156 157 |
# File 'lib/mxrb/runtime/native.rb', line 155 def store @store end |
Instance Method Details
#call(name, arguments = {}) ⇒ Object
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/mxrb/runtime/native.rb', line 167 def call(name, arguments = {}) flow = @flows[name] raise NativeRuntimeError, "microflow #{name} not found" unless flow snapshot = store.snapshot execute(flow, normalize_arguments(flow, arguments)) rescue StandardError store.restore(snapshot) if snapshot raise end |
#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.
180 181 182 |
# File 'lib/mxrb/runtime/native.rb', line 180 def count(entity, xpath = nil) filter_by_xpath(store.retrieve(entity.to_s), xpath.to_s, {}).size end |