Module: Sourced::Sync::ClassMethods

Defined in:
lib/sourced/sync.rb

Instance Method Summary collapse

Instance Method Details

#inherited(subclass) ⇒ Object



38
39
40
41
42
43
# File 'lib/sourced/sync.rb', line 38

def inherited(subclass)
  super
  sync_blocks.each do |blk|
    subclass.sync_blocks << blk
  end
end

#sync(callable = nil, &block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/sourced/sync.rb', line 49

def sync(callable = nil, &block)
  callable ||= block
  callable = case callable
             when Proc
               unless (2..3).include?(callable.arity)
                 raise ArgumentError,
                       'sync block must accept 2 or 3 arguments'
               end

               callable
             when ReactorInterface
               # Wrap reactors here
               # TODO:
               # If the sync reactor runs successfully
               # A). we want to ACK processed events for it in the offsets table
               # so that if the reactor is moved to async execution
               # it doesn't reprocess the same events again
               # B). The reactors .handle_events may return commands
               # Do we want to dispatch those commands inline?
               # Or is this another reason to have a separate async command bus
               SyncReactor.new(callable)
             when CallableInterface
               callable
             else
               raise ArgumentError, 'sync block must be a Proc, Sourced::ReactorInterface or #call interface'
             end

  sync_blocks << callable
end

#sync_blocksObject



45
46
47
# File 'lib/sourced/sync.rb', line 45

def sync_blocks
  @sync_blocks ||= []
end