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(available_at: nil, idempotency_key: nil, authorization_context: nil) ⇒ OperationDispatcher
- #destroy(authorization_context: nil) ⇒ Boolean
-
#initialize(actor_type:, actor_id:) ⇒ Reference
constructor
A new instance of Reference.
- #invoke_synchronously(operation, arguments, timeout:, idempotency_key:, authorization_context:) ⇒ Object
- #method_missing(name, *arguments, **keywords) ⇒ Object
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
- #snapshot(authorization_context: nil) ⇒ StateSnapshot
- #sync(timeout: 5.seconds, idempotency_key: nil, authorization_context: nil) ⇒ OperationDispatcher
- #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
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/solid_objects/reference.rb', line 76 def method_missing(name, *arguments, **keywords) return super if arguments.any? || block_given? if (name) || actor_query?(name) return invoke_synchronously( name, keywords, timeout: 5.seconds, idempotency_key: nil, authorization_context: nil ) end 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
128 129 130 |
# File 'lib/solid_objects/reference.rb', line 128 def actor_definition SolidObjects.registry.fetch(actor_type).definition end |
#actor_message?(name) ⇒ Boolean
118 119 120 |
# File 'lib/solid_objects/reference.rb', line 118 def (name) actor_definition..key?(name.to_sym) end |
#actor_query?(name) ⇒ Boolean
123 124 125 |
# File 'lib/solid_objects/reference.rb', line 123 def actor_query?(name) actor_definition.queries.key?(name.to_sym) end |
#async(available_at: nil, idempotency_key: nil, authorization_context: nil) ⇒ OperationDispatcher
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/solid_objects/reference.rb', line 20 def async(available_at: nil, idempotency_key: nil, authorization_context: nil) OperationDispatcher.new( actor_type:, handlers: actor_definition. ) do |operation, arguments| if (actor = Context.current_actor) actor.( reference: self, operation:, arguments:, available_at:, idempotency_key: ) next end SolidObjects.client.async( reference: self, operation:, arguments:, available_at:, idempotency_key:, authorization_context: ) end end |
#destroy(authorization_context: nil) ⇒ Boolean
66 67 68 |
# File 'lib/solid_objects/reference.rb', line 66 def destroy(authorization_context: nil) SolidObjects.client.destroy(self, authorization_context:) end |
#invoke_synchronously(operation, arguments, timeout:, idempotency_key:, authorization_context:) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/solid_objects/reference.rb', line 104 def invoke_synchronously(operation, arguments, timeout:, idempotency_key:, authorization_context:) raise ActorCallCycle, "actors cannot synchronously wait for another actor" if Context.current_actor SolidObjects.client.sync( reference: self, operation:, arguments:, timeout:, idempotency_key:, authorization_context: ) end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
92 93 94 |
# File 'lib/solid_objects/reference.rb', line 92 def respond_to_missing?(name, include_private = false) (name) || actor_query?(name) || super end |
#snapshot(authorization_context: nil) ⇒ StateSnapshot
71 72 73 |
# File 'lib/solid_objects/reference.rb', line 71 def snapshot(authorization_context: nil) SolidObjects.client.snapshot(self, authorization_context:) end |
#sync(timeout: 5.seconds, idempotency_key: nil, authorization_context: nil) ⇒ OperationDispatcher
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/solid_objects/reference.rb', line 48 def sync(timeout: 5.seconds, idempotency_key: nil, authorization_context: nil) raise ActorCallCycle, "actors cannot synchronously wait for another actor" if Context.current_actor OperationDispatcher.new( actor_type:, handlers: actor_definition..merge(actor_definition.queries) ) do |operation, arguments| invoke_synchronously( operation, arguments, timeout:, idempotency_key:, authorization_context: ) end end |
#to_s ⇒ String
97 98 99 |
# File 'lib/solid_objects/reference.rb', line 97 def to_s "#{actor_type}(#{actor_id.inspect})" end |