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.
-
#registration ⇒ Object
readonly
Returns the value of attribute registration.
-
#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:, registration:, view_context:, authorization_context:) ⇒ ComponentRenderer
constructor
A new instance of ComponentRenderer.
Constructor Details
#initialize(snapshot:, registration:, view_context:, authorization_context:) ⇒ ComponentRenderer
Returns a new instance of ComponentRenderer.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/solid_objects/component_renderer.rb', line 11 def initialize( snapshot:, registration:, view_context:, authorization_context: ) @snapshot = snapshot @registration = registration @view_context = view_context @authorization_context = end |
Instance Attribute Details
#authorization_context ⇒ Object (readonly)
Returns the value of attribute authorization_context.
52 53 54 |
# File 'lib/solid_objects/component_renderer.rb', line 52 def @authorization_context end |
#registration ⇒ Object (readonly)
Returns the value of attribute registration.
52 53 54 |
# File 'lib/solid_objects/component_renderer.rb', line 52 def registration @registration end |
#snapshot ⇒ Object (readonly)
Returns the value of attribute snapshot.
52 53 54 |
# File 'lib/solid_objects/component_renderer.rb', line 52 def snapshot @snapshot end |
#view_context ⇒ Object (readonly)
Returns the value of attribute view_context.
52 53 54 |
# File 'lib/solid_objects/component_renderer.rb', line 52 def view_context @view_context end |
Instance Method Details
#authorize_read!(observable_name) ⇒ void
This method returns an undefined value.
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/solid_objects/component_renderer.rb', line 58 def (observable_name) = SolidObjects.configuration..call( actor_type: snapshot.reference.actor_type, actor_id: snapshot.reference.actor_id, message_name: observable_name, arguments: registration., authorization_context: ) return if raise Unauthorized, "actor component query is not authorized" end |
#call ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/solid_objects/component_renderer.rb', line 24 def call [ registration.component_name, *registration.dependencies ].uniq.each do || () end actor = ComponentView.new( snapshot:, dependencies: registration.dependencies, authorization_context: ) view_context.render( partial: default_partial, locals: registration.locals.transform_keys(&:to_sym).merge( actor:, authorization_context:, component_key: registration.component_key ) ) rescue ActionView::MissingTemplate raise UnknownComponent, "unknown component #{registration.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
72 73 74 75 76 77 |
# File 'lib/solid_objects/component_renderer.rb', line 72 def default_partial actor_name = snapshot.actor_class.name raise InvalidActor, "anonymous actors cannot render reactive components" unless actor_name "actors/#{actor_name.underscore}/#{registration.component_name}" end |