Class: ServerComponent::ComponentRouter

Inherits:
Object
  • Object
show all
Defined in:
lib/server_component/component_router.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace = nil) ⇒ ComponentRouter

Returns a new instance of 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

#componentsObject (readonly)

Returns the value of attribute components.



5
6
7
# File 'lib/server_component/component_router.rb', line 5

def components
  @components
end

#namespaceObject (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_scriptObject



26
27
28
# File 'lib/server_component/component_router.rb', line 26

def context_script
  ServerComponent.context_script
end

#to_jsonObject



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