Module: Sourced::Decide

Defined in:
lib/sourced/decide.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

PREFIX =
'command'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
# File 'lib/sourced/decide.rb', line 7

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

Instance Method Details

#decide(*args) ⇒ Object

Run command handler methods defined with the .decide(Command, &) macro The signature will depend on how the command handler is defined Example:

decide(state, command)
decide(command)


18
19
20
21
22
23
24
25
26
# File 'lib/sourced/decide.rb', line 18

def decide(*args)
  events = case args
           in [command]
             send(Sourced.message_method_name(PREFIX, command.class.name), command)
           in [state, command]
             send(Sourced.message_method_name(PREFIX, command.class.name), state, command)
           end
  [events].flatten.compact
end