Class: SolidObjects::Reference
- Inherits:
-
Object
- Object
- SolidObjects::Reference
- Defined in:
- lib/solid_objects/reference.rb,
sig/generated/lib/solid_objects/reference.rbs
Instance Attribute Summary collapse
- #actor_id ⇒ Object readonly
- #actor_type ⇒ Object readonly
Instance Method Summary collapse
- #actor_definition ⇒ ActorDefinition
- #actor_message?(name) ⇒ Boolean
- #actor_query?(name) ⇒ Boolean
- #ask(message_name, timeout: 5.seconds, idempotency_key: nil, authorization_context: nil, **arguments) ⇒ Object
- #destroy(authorization_context: nil) ⇒ Boolean
-
#initialize(actor_type:, actor_id:) ⇒ Reference
constructor
A new instance of Reference.
- #method_missing(name, *arguments, **keywords) ⇒ Object
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
- #tell(message_name, available_at: nil, idempotency_key: nil, authorization_context: nil, **arguments) ⇒ MessageReference, Actor::OutboundMessageIntent
- #to_s ⇒ String
Constructor Details
#initialize(actor_type:, actor_id:) ⇒ Reference
Returns a new instance of Reference.
11 12 13 14 15 16 17 |
# File 'lib/solid_objects/reference.rb', line 11 def initialize(actor_type:, actor_id:) raise InvalidActor, "actor ID cannot be empty" if actor_id.empty? @actor_type = actor_type @actor_id = actor_id freeze end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *arguments, **keywords) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/solid_objects/reference.rb', line 61 def method_missing(name, *arguments, **keywords) return super if arguments.any? || block_given? return tell(name, **keywords) if (name) return Serialization.readonly_copy(ask(name, **keywords)) if actor_query?(name) super end |
Instance Attribute Details
#actor_id ⇒ Object (readonly)
8 9 10 |
# File 'lib/solid_objects/reference.rb', line 8 def actor_id @actor_id end |
#actor_type ⇒ Object (readonly)
8 9 10 |
# File 'lib/solid_objects/reference.rb', line 8 def actor_type @actor_type end |
Instance Method Details
#actor_definition ⇒ ActorDefinition
92 93 94 |
# File 'lib/solid_objects/reference.rb', line 92 def actor_definition SolidObjects.registry.fetch(actor_type).definition end |
#actor_message?(name) ⇒ Boolean
82 83 84 |
# File 'lib/solid_objects/reference.rb', line 82 def (name) actor_definition..key?(name.to_sym) end |
#actor_query?(name) ⇒ Boolean
87 88 89 |
# File 'lib/solid_objects/reference.rb', line 87 def actor_query?(name) actor_definition.queries.key?(name.to_sym) end |
#ask(message_name, timeout: 5.seconds, idempotency_key: nil, authorization_context: nil, **arguments) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/solid_objects/reference.rb', line 42 def ask(, timeout: 5.seconds, idempotency_key: nil, authorization_context: nil, **arguments) raise ActorCallCycle, "actors cannot synchronously wait for another actor" if Context.current_actor SolidObjects.client.ask( self, , arguments, timeout:, idempotency_key:, authorization_context: ) end |
#destroy(authorization_context: nil) ⇒ Boolean
56 57 58 |
# File 'lib/solid_objects/reference.rb', line 56 def destroy(authorization_context: nil) SolidObjects.client.destroy(self, authorization_context:) end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
70 71 72 |
# File 'lib/solid_objects/reference.rb', line 70 def respond_to_missing?(name, include_private = false) (name) || actor_query?(name) || super end |
#tell(message_name, available_at: nil, idempotency_key: nil, authorization_context: nil, **arguments) ⇒ MessageReference, Actor::OutboundMessageIntent
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/solid_objects/reference.rb', line 20 def tell(, available_at: nil, idempotency_key: nil, authorization_context: nil, **arguments) if (actor = Context.current_actor) return actor.( self, , arguments, available_at:, idempotency_key: ) end SolidObjects.client.tell( self, , arguments, available_at:, idempotency_key:, authorization_context: ) end |
#to_s ⇒ String
75 76 77 |
# File 'lib/solid_objects/reference.rb', line 75 def to_s "#{actor_type}(#{actor_id.inspect})" end |