Class: SolidObjects::ComponentRenderer
- Inherits:
-
Object
- Object
- SolidObjects::ComponentRenderer
- Defined in:
- lib/solid_objects/component_renderer.rb,
sig/generated/lib/solid_objects/component_renderer.rbs
Instance Attribute Summary collapse
-
#authorization_context ⇒ Object
readonly
Returns the value of attribute authorization_context.
-
#component_name ⇒ Object
readonly
Returns the value of attribute component_name.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#snapshot ⇒ Object
readonly
Returns the value of attribute snapshot.
-
#view_context ⇒ Object
readonly
Returns the value of attribute view_context.
Instance Method Summary collapse
- #authorize_read!(observable_name) ⇒ void
- #call ⇒ Object
- #default_partial ⇒ String
-
#initialize(snapshot:, component_name:, dependencies:, view_context:, authorization_context:) ⇒ ComponentRenderer
constructor
A new instance of ComponentRenderer.
Constructor Details
#initialize(snapshot:, component_name:, dependencies:, view_context:, authorization_context:) ⇒ ComponentRenderer
Returns a new instance of ComponentRenderer.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/solid_objects/component_renderer.rb', line 12 def initialize( snapshot:, component_name:, dependencies:, view_context:, authorization_context: ) @snapshot = snapshot @component_name = component_name @dependencies = dependencies @view_context = view_context @authorization_context = end |
Instance Attribute Details
#authorization_context ⇒ Object (readonly)
Returns the value of attribute authorization_context.
54 55 56 |
# File 'lib/solid_objects/component_renderer.rb', line 54 def @authorization_context end |
#component_name ⇒ Object (readonly)
Returns the value of attribute component_name.
54 55 56 |
# File 'lib/solid_objects/component_renderer.rb', line 54 def component_name @component_name end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
54 55 56 |
# File 'lib/solid_objects/component_renderer.rb', line 54 def dependencies @dependencies end |
#snapshot ⇒ Object (readonly)
Returns the value of attribute snapshot.
54 55 56 |
# File 'lib/solid_objects/component_renderer.rb', line 54 def snapshot @snapshot end |
#view_context ⇒ Object (readonly)
Returns the value of attribute view_context.
54 55 56 |
# File 'lib/solid_objects/component_renderer.rb', line 54 def view_context @view_context end |
Instance Method Details
#authorize_read!(observable_name) ⇒ void
This method returns an undefined value.
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/solid_objects/component_renderer.rb', line 61 def (observable_name) = SolidObjects.configuration..call( actor_type: snapshot.reference.actor_type, actor_id: snapshot.reference.actor_id, message_name: observable_name, arguments: {}, authorization_context: ) return if raise Unauthorized, "actor component query is not authorized" end |
#call ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/solid_objects/component_renderer.rb', line 27 def call [ component_name, *dependencies ].uniq.each do || () end actor = ComponentView.new( snapshot:, dependencies:, authorization_context: ) view_context.render( partial: default_partial, locals: { actor:, authorization_context: } ) rescue ActionView::MissingTemplate raise UnknownComponent, "unknown component #{component_name.inspect} for #{snapshot.reference.actor_type}" rescue ActionView::Template::Error => error raise error.cause if error.cause.is_a?(SolidObjects::Error) raise end |
#default_partial ⇒ String
75 76 77 78 79 80 |
# File 'lib/solid_objects/component_renderer.rb', line 75 def default_partial actor_name = snapshot.actor_class.name raise InvalidActor, "anonymous actors cannot render reactive components" unless actor_name "actors/#{actor_name.underscore}/#{component_name}" end |