Class: Conreality::Database::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/conreality/database/transaction.rb

Overview

Encapsulates a database transaction.

Theaters collapse

Objects collapse

Events collapse

Messaging collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Transaction

Returns a new instance of Transaction.

Parameters:


7
8
9
# File 'lib/conreality/database/transaction.rb', line 7

def initialize(client)
  @client = client
end

Instance Method Details

#each_object(&block) ⇒ Object

TODO:

51
52
53
# File 'lib/conreality/database/transaction.rb', line 51

def each_object(&block)
  # TODO
end

#each_theater(&block) ⇒ Object

TODO:

32
33
34
# File 'lib/conreality/database/transaction.rb', line 32

def each_theater(&block)
  # TODO
end

#find_event(id) ⇒ Event

TODO:

Returns the event.

Returns:


62
63
64
# File 'lib/conreality/database/transaction.rb', line 62

def find_event(id)
  # TODO
end

#find_message(id) ⇒ Message

TODO:

Returns the message.

Returns:


87
88
89
# File 'lib/conreality/database/transaction.rb', line 87

def find_message(id)
  # TODO
end

#find_object(uuid) ⇒ Object

Returns the object identified by the given UUID.

Parameters:

  • uuid (String)

    the object's UUID

Returns:


45
46
47
# File 'lib/conreality/database/transaction.rb', line 45

def find_object(uuid)
  Conreality::Object.new(@client, uuid)
end

#find_theater(uuid) ⇒ Theater

Returns the theater identified by the given UUID.

Parameters:

  • uuid (String)

    the theater's UUID

Returns:


26
27
28
# File 'lib/conreality/database/transaction.rb', line 26

def find_theater(uuid)
  Conreality::Theater.new(@client, uuid)
end

#inspectString

Returns a developer-friendly representation of this transaction.

Returns:

  • (String)

15
16
17
# File 'lib/conreality/database/transaction.rb', line 15

def inspect
  sprintf("#<%s:%#0x>", self.class.name, self.__id__)
end

#send_event(predicate, subject, object = nil) ⇒ Event

Returns the sent event.

Parameters:

  • predicate (String)

    a predicate string

  • subject (Object, UUID)

    the source object

  • object (Object, UUID, nil) (defaults to: nil)

    the target object, if any

Returns:

  • (Event)

    the sent event


71
72
73
74
75
76
77
78
# File 'lib/conreality/database/transaction.rb', line 71

def send_event(predicate, subject, object = nil)
  predicate = predicate.to_s
  subject   = (subject.respond_to?(:uuid) ? subject.uuid : subject).to_s
  object    = object ? (object.respond_to?(:uuid) ? object.uuid : object).to_s : nil

  result = @client.call_proc_with_result(:event_send, args: [subject, predicate, object])
  result ? Conreality::Event.new(@client, result.to_i) : nil
end

#send_message(sender, text) ⇒ Message

TODO:

Support for audio messages.

Returns the sent message.

Parameters:

  • sender (Object, UUID)

    the sending asset or player

  • text (String)

    the message contents as text

Returns:


96
97
98
99
100
101
102
# File 'lib/conreality/database/transaction.rb', line 96

def send_message(sender, text)
  sender = (sender.respond_to?(:uuid) ? sender.uuid : sender).to_s
  text = text.to_s

  result = @client.call_proc_with_result(:message_send, args: [sender, text])
  result ? Conreality::Message.new(@client, result.to_i) : nil
end