Class: SolidObjects::ComponentView

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(snapshot:, dependencies:, authorization_context:) ⇒ ComponentView

Returns a new instance of ComponentView.

RBS:

  • (snapshot: ActorSnapshot, dependencies: Array[String], authorization_context: untyped) -> void

Parameters:

  • snapshot: (ActorSnapshot)
  • dependencies: (Array[String])
  • authorization_context: (Object)


12
13
14
15
16
# File 'lib/solid_objects/component_view.rb', line 12

def initialize(snapshot:, dependencies:, authorization_context:)
  @snapshot = snapshot
  @dependencies = dependencies
  @authorization_context = authorization_context
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)


35
36
37
38
39
40
# File 'lib/solid_objects/component_view.rb', line 35

def method_missing(name, *arguments, **keywords)
  return super unless arguments.empty? && keywords.empty?
  return observable_value(name) if observable?(name)

  super
end

Instance Attribute Details

#authorization_contextObject (readonly)

RBS:

  • @snapshot: ActorSnapshot

  • @dependencies: Array[String]

  • @authorization_context: untyped

Returns:

  • (Object)


9
10
11
# File 'lib/solid_objects/component_view.rb', line 9

def authorization_context
  @authorization_context
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.

Returns:

  • (Object)


49
50
51
# File 'lib/solid_objects/component_view.rb', line 49

def dependencies
  @dependencies
end

#snapshotObject (readonly)

Returns the value of attribute snapshot.

Returns:

  • (Object)


49
50
51
# File 'lib/solid_objects/component_view.rb', line 49

def snapshot
  @snapshot
end

Instance Method Details

#actor_idString

RBS:

  • () -> String

Returns:

  • (String)


24
25
26
# File 'lib/solid_objects/component_view.rb', line 24

def actor_id
  reference.actor_id
end

#observable?(name) ⇒ Boolean

RBS:

  • (Symbol | String) -> bool

Parameters:

  • (Symbol, String)

Returns:

  • (Boolean)


52
53
54
# File 'lib/solid_objects/component_view.rb', line 52

def observable?(name)
  snapshot.actor_class.definition.observables.key?(name.to_sym)
end

#observable_value(name) ⇒ Object

RBS:

  • (Symbol | String) -> untyped

Parameters:

  • (Symbol, String)

Returns:

  • (Object)


57
58
59
60
61
62
63
64
65
# File 'lib/solid_objects/component_view.rb', line 57

def observable_value(name)
  dependency = name.to_s
  unless dependencies.include?(dependency)
    raise UnknownComponentDependency,
      "observable #{dependency.inspect} is not declared by this component"
  end

  snapshot.observable_value(dependency)
end

#referenceReference

RBS:

  • () -> Reference

Returns:



19
20
21
# File 'lib/solid_objects/component_view.rb', line 19

def reference
  snapshot.reference
end

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

RBS:

  • (Symbol, bool) -> bool

Parameters:

  • (Symbol)
  • (Boolean)

Returns:

  • (Boolean)


43
44
45
# File 'lib/solid_objects/component_view.rb', line 43

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

#statevoid

This method returns an undefined value.

RBS:

  • () -> void



29
30
31
32
# File 'lib/solid_objects/component_view.rb', line 29

def state
  raise UnknownComponentDependency,
    "reactive components must read declared observables instead of actor.state"
end