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
- #async(message_name, available_at: nil, idempotency_key: nil, authorization_context: nil, **arguments) ⇒ MessageReference?
- #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
- #snapshot(authorization_context: nil) ⇒ StateSnapshot
- #sync(message_name, timeout: 5.seconds, idempotency_key: nil, authorization_context: nil, **arguments) ⇒ Object
- #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
67 68 69 70 71 72 |
# File 'lib/solid_objects/reference.rb', line 67 def method_missing(name, *arguments, **keywords) return super if arguments.any? || block_given? return sync(name, **keywords) if (name) || 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
97 98 99 |
# File 'lib/solid_objects/reference.rb', line 97 def actor_definition SolidObjects.registry.fetch(actor_type).definition end |
#actor_message?(name) ⇒ Boolean
87 88 89 |
# File 'lib/solid_objects/reference.rb', line 87 def (name) actor_definition..key?(name.to_sym) end |
#actor_query?(name) ⇒ Boolean
92 93 94 |
# File 'lib/solid_objects/reference.rb', line 92 def actor_query?(name) actor_definition.queries.key?(name.to_sym) end |
#async(message_name, available_at: nil, idempotency_key: nil, authorization_context: nil, **arguments) ⇒ MessageReference?
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/solid_objects/reference.rb', line 20 def async(, available_at: nil, idempotency_key: nil, authorization_context: nil, **arguments) if (actor = Context.current_actor) actor.( self, , arguments, available_at:, idempotency_key: ) return end SolidObjects.client.async( self, , arguments, available_at:, idempotency_key:, authorization_context: ) end |
#destroy(authorization_context: nil) ⇒ Boolean
57 58 59 |
# File 'lib/solid_objects/reference.rb', line 57 def destroy(authorization_context: nil) SolidObjects.client.destroy(self, authorization_context:) end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
75 76 77 |
# File 'lib/solid_objects/reference.rb', line 75 def respond_to_missing?(name, include_private = false) (name) || actor_query?(name) || super end |
#snapshot(authorization_context: nil) ⇒ StateSnapshot
62 63 64 |
# File 'lib/solid_objects/reference.rb', line 62 def snapshot(authorization_context: nil) SolidObjects.client.snapshot(self, authorization_context:) end |
#sync(message_name, timeout: 5.seconds, idempotency_key: nil, authorization_context: nil, **arguments) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/solid_objects/reference.rb', line 43 def sync(, 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.sync( self, , arguments, timeout:, idempotency_key:, authorization_context: ) end |
#to_s ⇒ String
80 81 82 |
# File 'lib/solid_objects/reference.rb', line 80 def to_s "#{actor_type}(#{actor_id.inspect})" end |