Class: Conreality::Action

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

Overview

A transaction-scoped action.

Instance Attribute Summary collapse

Events collapse

Messaging collapse

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ Action

Returns a new instance of Action.

Parameters:



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

def initialize(session)
  @session = session
end

Instance Attribute Details

#sessionSession (readonly)

The client session this actions belongs to.

Returns:



11
12
13
# File 'lib/conreality/action.rb', line 11

def session
  @session
end

Instance Method Details

#inspectString

Returns a developer-friendly representation of this action.

Returns:

  • (String)


23
24
25
# File 'lib/conreality/action.rb', line 23

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



34
35
36
37
38
39
40
41
# File 'lib/conreality/action.rb', line 34

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 = @session.client.call_proc_with_result(:event_send, args: [predicate, subject, object])
  result ? Conreality::Event.new(@session, 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:



52
53
54
55
56
57
58
# File 'lib/conreality/action.rb', line 52

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

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