Module: Sourced::Sync

Included in:
Decider, Projector
Defined in:
lib/sourced/sync.rb

Defined Under Namespace

Modules: ClassMethods Classes: SyncReactor

Constant Summary collapse

CallableInterface =
Sourced::Types::Interface[:call]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
# File 'lib/sourced/sync.rb', line 5

def self.included(base)
  super
  base.extend ClassMethods
end

Instance Method Details

#run_sync_blocks(state, command, events) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sourced/sync.rb', line 10

def run_sync_blocks(state, command, events)
  self.class.sync_blocks.each do |blk|
    case blk
    when Proc
      if blk.arity == 2 # (command, events)
        instance_exec(command, events, &blk)
      else # (state, command, events)
        instance_exec(state, command, events, &blk)
      end
    else
      blk.call(state, command, events)
    end
  end
end