Class: Conreality::Action
- Inherits:
-
Object
- Object
- Conreality::Action
- Defined in:
- lib/conreality/action.rb
Overview
A transaction-scoped action.
Instance Attribute Summary collapse
-
#session ⇒ Session
readonly
The client session this actions belongs to.
Events collapse
-
#send_event(predicate, subject, object = nil) ⇒ Event
The sent event.
Messaging collapse
-
#send_message(sender, text) ⇒ Message
The sent message.
Instance Method Summary collapse
-
#initialize(session) ⇒ Action
constructor
A new instance of Action.
-
#inspect ⇒ String
Returns a developer-friendly representation of this action.
Constructor Details
#initialize(session) ⇒ Action
Returns a new instance of Action.
15 16 17 |
# File 'lib/conreality/action.rb', line 15 def initialize(session) @session = session end |
Instance Attribute Details
#session ⇒ Session (readonly)
The client session this actions belongs to.
11 12 13 |
# File 'lib/conreality/action.rb', line 11 def session @session end |
Instance Method Details
#inspect ⇒ String
Returns a developer-friendly representation of this action.
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.
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.
52 53 54 55 56 57 58 |
# File 'lib/conreality/action.rb', line 52 def (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 |