Class: Tiler::WidgetRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/tiler/widget_registry.rb

Instance Method Summary collapse

Constructor Details

#initializeWidgetRegistry

Returns a new instance of WidgetRegistry.



5
6
7
# File 'lib/tiler/widget_registry.rb', line 5

def initialize
  @widgets = {}
end

Instance Method Details

#[](type) ⇒ Object



15
16
17
# File 'lib/tiler/widget_registry.rb', line 15

def [](type)
  @widgets[type.to_s]
end

#each(&block) ⇒ Object



33
34
35
# File 'lib/tiler/widget_registry.rb', line 33

def each(&block)
  @widgets.each(&block)
end

#fetch(type) ⇒ Object



25
26
27
# File 'lib/tiler/widget_registry.rb', line 25

def fetch(type)
  @widgets.fetch(type.to_s) { raise Error, "Unknown widget type: #{type}" }
end

#options_for_selectObject



37
38
39
# File 'lib/tiler/widget_registry.rb', line 37

def options_for_select
  @widgets.map { |type, klass| [ klass.label, type ] }
end

#register(type, klass: nil, partial: nil, label: nil, query: nil, col_spans: [ 1, 2 ]) ⇒ Object



9
10
11
12
13
# File 'lib/tiler/widget_registry.rb', line 9

def register(type, klass: nil, partial: nil, label: nil, query: nil, col_spans: [ 1, 2 ])
  type = type.to_s
  klass ||= build_anonymous(type, partial:, label:, query:, col_spans:)
  @widgets[type] = klass
end

#typesObject



29
30
31
# File 'lib/tiler/widget_registry.rb', line 29

def types
  @widgets.keys
end

#unregister(type) ⇒ Object

Drop a widget from the registry. Used by Tiler::UserWidget when a no-code widget row is destroyed.



21
22
23
# File 'lib/tiler/widget_registry.rb', line 21

def unregister(type)
  @widgets.delete(type.to_s)
end