Class: SolidObjects::StateSnapshot

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reference) ⇒ StateSnapshot

Returns a new instance of StateSnapshot.

RBS:

  • (Reference) -> void

Parameters:



9
10
11
12
13
# File 'lib/solid_objects/state_snapshot.rb', line 9

def initialize(reference)
  actor_snapshot = ActorSnapshot.new(reference)
  @actor_class = actor_snapshot.actor_class
  @data = Serialization.readonly_copy(actor_snapshot.actor.state.to_h)
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)


21
22
23
24
25
# File 'lib/solid_objects/state_snapshot.rb', line 21

def method_missing(name, *arguments, **keywords)
  return data.fetch(name.to_s) if arguments.empty? && keywords.empty? && attribute?(name)

  super
end

Instance Attribute Details

#actor_classObject (readonly)

Returns the value of attribute actor_class.

Returns:

  • (Object)


34
35
36
# File 'lib/solid_objects/state_snapshot.rb', line 34

def actor_class
  @actor_class
end

#dataObject (readonly)

Returns the value of attribute data.

Returns:

  • (Object)


34
35
36
# File 'lib/solid_objects/state_snapshot.rb', line 34

def data
  @data
end

Instance Method Details

#attribute?(name) ⇒ Boolean

RBS:

  • (Symbol | String) -> bool

Parameters:

  • (Symbol, String)

Returns:

  • (Boolean)


37
38
39
# File 'lib/solid_objects/state_snapshot.rb', line 37

def attribute?(name)
  actor_class.definition.state_definition.to_h.key?(name.to_sym)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

RBS:

  • (Symbol, bool) -> bool

Parameters:

  • (Symbol)
  • (Boolean)

Returns:

  • (Boolean)


28
29
30
# File 'lib/solid_objects/state_snapshot.rb', line 28

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

#to_hHash[String, untyped]

RBS:

  • () -> Hash[String, untyped]

Returns:

  • (Hash[String, untyped])


16
17
18
# File 'lib/solid_objects/state_snapshot.rb', line 16

def to_h
  data
end