Class: A2UI::SurfaceManager
- Inherits:
-
Object
- Object
- A2UI::SurfaceManager
- Extended by:
- T::Sig
- Defined in:
- lib/a2ui/modules/surface_manager.rb
Instance Method Summary collapse
- #create(surface_id:, request:, data: '{}') ⇒ Object
- #delete(surface_id) ⇒ Object
- #get(surface_id) ⇒ Object
- #handle_action(action:, business_rules: '') ⇒ Object
-
#initialize ⇒ SurfaceManager
constructor
A new instance of SurfaceManager.
- #update(surface_id:, request:) ⇒ Object
Constructor Details
#initialize ⇒ SurfaceManager
Returns a new instance of SurfaceManager.
9 10 11 12 13 14 |
# File 'lib/a2ui/modules/surface_manager.rb', line 9 def initialize @surfaces = T.let({}, T::Hash[String, Surface]) @generator = T.let(UIGenerator.new, UIGenerator) @updater = T.let(UIUpdater.new, UIUpdater) @action_handler = T.let(ActionHandler.new, ActionHandler) end |
Instance Method Details
#create(surface_id:, request:, data: '{}') ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/a2ui/modules/surface_manager.rb', line 17 def create(surface_id:, request:, data: '{}') result = @generator.call( request: request, surface_id: surface_id, available_data: data ) surface = Surface.new(surface_id) surface.set_components(result.root_id, result.components) surface.apply_data_updates(result.initial_data) @surfaces[surface_id] = surface end |
#delete(surface_id) ⇒ Object
60 61 62 |
# File 'lib/a2ui/modules/surface_manager.rb', line 60 def delete(surface_id) @surfaces.delete(surface_id) end |
#get(surface_id) ⇒ Object
55 56 57 |
# File 'lib/a2ui/modules/surface_manager.rb', line 55 def get(surface_id) @surfaces[surface_id] end |
#handle_action(action:, business_rules: '') ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/a2ui/modules/surface_manager.rb', line 44 def handle_action(action:, business_rules: '') surface = @surfaces.fetch(action.surface_id) @action_handler.call( action: action, current_data: surface.to_json, business_rules: business_rules ) end |
#update(surface_id:, request:) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/a2ui/modules/surface_manager.rb', line 32 def update(surface_id:, request:) surface = @surfaces.fetch(surface_id) @updater.call( request: request, surface_id: surface_id, current_components: surface.components.values, current_data: surface.to_json ) end |