Class: LifecycleVM::Then
- Inherits:
-
Object
- Object
- LifecycleVM::Then
- Defined in:
- lib/lifecycle_vm/then.rb
Defined Under Namespace
Classes: AnonymousState, InvalidBranch, InvalidCond, InvalidThen, Simple
Class Method Summary collapse
Instance Method Summary collapse
- #call(vm) ⇒ Object
-
#initialize(options) ⇒ Then
constructor
A new instance of Then.
Constructor Details
#initialize(options) ⇒ Then
Returns a new instance of Then.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/lifecycle_vm/then.rb', line 52 def initialize() if !(.kind_of?(Hash) && .key?(:case) && .key?(:when)) raise InvalidThen.new() end @cond = [:case] @branches = [:when].transform_values do |value| case value when Hash if value.key?(:case) Then.new(value) elsif value.key?(:then) AnonymousState.new(value) else raise InvalidBranch.new(value, ) end when Symbol Simple.new(value) else raise InvalidBranch.new(value, ) end end end |
Class Method Details
.new(options) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/lifecycle_vm/then.rb', line 44 def self.new() if .kind_of?(Symbol) return Simple.new() else super end end |
Instance Method Details
#call(vm) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/lifecycle_vm/then.rb', line 110 def call(vm) state_name = vm.current_state.name conditional_name = @cond.name logger = vm.logger logger&.debug(:conditional_check, state: state_name, ctx: vm, conditional: conditional_name) value = @cond.call(vm.memory) logger&.debug(:conditional_result, state: state_name, ctx: vm, conditional: conditional_name, result: value) branch = @branches[value] raise InvalidCond.new(value, @cond, @branches, vm) unless branch.respond_to?(:call) branch.call(vm) end |