Class: ServerComponent::ComponentRouter
- Inherits:
-
Object
- Object
- ServerComponent::ComponentRouter
- Defined in:
- lib/server_component/component_router.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
- #add_component(name) ⇒ Object
- #context_script ⇒ Object
-
#initialize(namespace = nil) ⇒ ComponentRouter
constructor
A new instance of ComponentRouter.
- #to_json ⇒ Object
Constructor Details
#initialize(namespace = nil) ⇒ ComponentRouter
7 8 9 10 |
# File 'lib/server_component/component_router.rb', line 7 def initialize(namespace = nil) @namespace = namespace @components = [] end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
5 6 7 |
# File 'lib/server_component/component_router.rb', line 5 def components @components end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
5 6 7 |
# File 'lib/server_component/component_router.rb', line 5 def namespace @namespace end |
Instance Method Details
#add_component(name) ⇒ Object
22 23 24 |
# File 'lib/server_component/component_router.rb', line 22 def add_component(name) @components << name.to_sym end |
#context_script ⇒ Object
26 27 28 |
# File 'lib/server_component/component_router.rb', line 26 def context_script ServerComponent.context_script end |
#to_json ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/server_component/component_router.rb', line 12 def to_json h = {} h[:components] = components.each_with_object({}) do |component, json| component_controller_class = find_component_controller_class(component) json[component] = component_controller_class.to_json end h[:context_script] = context_script h end |