Class: SolidObjects::ComponentView
- Inherits:
-
Object
- Object
- SolidObjects::ComponentView
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.
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
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_context ⇒ Object
9
10
11
|
# File 'lib/solid_objects/component_view.rb', line 9
def authorization_context
@authorization_context
end
|
#dependencies ⇒ Object
Returns the value of attribute dependencies.
49
50
51
|
# File 'lib/solid_objects/component_view.rb', line 49
def dependencies
@dependencies
end
|
#snapshot ⇒ Object
Returns the value of attribute snapshot.
49
50
51
|
# File 'lib/solid_objects/component_view.rb', line 49
def snapshot
@snapshot
end
|
Instance Method Details
#actor_id ⇒ String
24
25
26
|
# File 'lib/solid_objects/component_view.rb', line 24
def actor_id
reference.actor_id
end
|
#observable?(name) ⇒ 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
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
|
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
43
44
45
|
# File 'lib/solid_objects/component_view.rb', line 43
def respond_to_missing?(name, include_private = false)
observable?(name) || super
end
|
#state ⇒ void
This method returns an undefined value.
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
|