Class: SolidObjects::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/solid_objects/reference.rb,
sig/generated/lib/solid_objects/reference.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actor_type:, actor_id:) ⇒ Reference

Returns a new instance of Reference.

RBS:

  • (actor_type: String, actor_id: String) -> void

Parameters:

  • actor_type: (String)
  • actor_id: (String)


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

RBS:

  • (Symbol, *untyped, **untyped) -> untyped

Parameters:

  • (Symbol)
  • (Object)
  • (Object)

Returns:

  • (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 actor_message?(name) || actor_query?(name)

  super
end

Instance Attribute Details

#actor_idObject (readonly)

RBS:

  • @actor_type: String

  • @actor_id: String

Returns:

  • (Object)


8
9
10
# File 'lib/solid_objects/reference.rb', line 8

def actor_id
  @actor_id
end

#actor_typeObject (readonly)

RBS:

  • @actor_type: String

  • @actor_id: String

Returns:

  • (Object)


8
9
10
# File 'lib/solid_objects/reference.rb', line 8

def actor_type
  @actor_type
end

Instance Method Details

#actor_definitionActorDefinition

RBS:

  • () -> ActorDefinition

Returns:



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

RBS:

  • (Symbol | String) -> bool

Parameters:

  • (Symbol, String)

Returns:

  • (Boolean)


87
88
89
# File 'lib/solid_objects/reference.rb', line 87

def actor_message?(name)
  actor_definition.messages.key?(name.to_sym)
end

#actor_query?(name) ⇒ Boolean

RBS:

  • (Symbol | String) -> bool

Parameters:

  • (Symbol, String)

Returns:

  • (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?

RBS:

  • (Symbol | String, ?available_at: Time?, ?idempotency_key: String?, ?authorization_context: untyped, **untyped) -> MessageReference?

Parameters:

  • (Symbol, String)
  • available_at: (Time, nil) (defaults to: nil)
  • idempotency_key: (String, nil) (defaults to: nil)
  • authorization_context: (Object) (defaults to: nil)
  • (Object)

Returns:



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(message_name, available_at: nil, idempotency_key: nil, authorization_context: nil, **arguments)
  if (actor = Context.current_actor)
    actor.stage_outbound_message(
      self,
      message_name,
      arguments,
      available_at:,
      idempotency_key:
    )
    return
  end

  SolidObjects.client.async(
    self,
    message_name,
    arguments,
    available_at:,
    idempotency_key:,
    authorization_context:
  )
end

#destroy(authorization_context: nil) ⇒ Boolean

RBS:

  • (?authorization_context: untyped) -> bool

Parameters:

  • authorization_context: (Object) (defaults to: nil)

Returns:

  • (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

RBS:

  • (Symbol, bool) -> bool

Parameters:

  • (Symbol)
  • (Boolean)

Returns:

  • (Boolean)


75
76
77
# File 'lib/solid_objects/reference.rb', line 75

def respond_to_missing?(name, include_private = false)
  actor_message?(name) || actor_query?(name) || super
end

#snapshot(authorization_context: nil) ⇒ StateSnapshot

RBS:

  • (?authorization_context: untyped) -> StateSnapshot

Parameters:

  • authorization_context: (Object) (defaults to: nil)

Returns:



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

RBS:

  • (Symbol | String, ?timeout: Numeric, ?idempotency_key: String?, ?authorization_context: untyped, **untyped) -> untyped

Parameters:

  • (Symbol, String)
  • timeout: (Numeric) (defaults to: 5.seconds)
  • idempotency_key: (String, nil) (defaults to: nil)
  • authorization_context: (Object) (defaults to: nil)
  • (Object)

Returns:

  • (Object)


43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/solid_objects/reference.rb', line 43

def sync(message_name, 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,
    message_name,
    arguments,
    timeout:,
    idempotency_key:,
    authorization_context:
  )
end

#to_sString

RBS:

  • () -> String

Returns:

  • (String)


80
81
82
# File 'lib/solid_objects/reference.rb', line 80

def to_s
  "#{actor_type}(#{actor_id.inspect})"
end