Module: Estore::Commands::Command

Included in:
Append, CatchUpSubscription, LiveSubscription, Ping, ReadBatch, ReadForward
Defined in:
lib/estore/commands/base.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#uuidObject (readonly)

Returns the value of attribute uuid.



4
5
6
# File 'lib/estore/commands/base.rb', line 4

def uuid
  @uuid
end

Instance Method Details

#handle(message) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/estore/commands/base.rb', line 37

def handle(message)
  handler = self.class.handlers[message.class]

  if handler
    send(handler, message) unless handler == :ignore
  else
    $stderr.puts "#{message.class} arrived but not handled by "\
      "command #{self.class}"
  end
end

#initialize(connection) ⇒ Object



12
13
14
15
# File 'lib/estore/commands/base.rb', line 12

def initialize(connection)
  @connection = connection
  @uuid = SecureRandom.uuid
end

#promiseObject



33
34
35
# File 'lib/estore/commands/base.rb', line 33

def promise
  @promise ||= Promise.new(@uuid)
end

#register!Object



17
18
19
# File 'lib/estore/commands/base.rb', line 17

def register!
  @connection.register(self)
end

#reject!(error) ⇒ Object



25
26
27
# File 'lib/estore/commands/base.rb', line 25

def reject!(error)
  @promise.reject(error) if @promise
end

#remove!Object



21
22
23
# File 'lib/estore/commands/base.rb', line 21

def remove!
  @connection.remove(self)
end

#write(command, message = nil) ⇒ Object



29
30
31
# File 'lib/estore/commands/base.rb', line 29

def write(command, message = nil)
  @connection.write(@uuid, command, message)
end