class Suricate::WidgetConfigurationsBuilder
Attributes
configurations[R]
Public Class Methods
new(template_repository)
click to toggle source
# File lib/suricate/configuration/widget_configurations_builder.rb, line 7 def initialize(template_repository) @template_repository = template_repository @configurations = [] end
Public Instance Methods
counter(id, collector, options = {})
click to toggle source
# File lib/suricate/configuration/widget_configurations_builder.rb, line 12 def counter(id, collector, options = {}) register(id, CounterWidget, collector, options) end
line_chart(id, collector, options = {})
click to toggle source
# File lib/suricate/configuration/widget_configurations_builder.rb, line 16 def line_chart(id, collector, options = {}) register(id, LineChartWidget, collector, options) end
register(id, klass, collector, options = {})
click to toggle source
# File lib/suricate/configuration/widget_configurations_builder.rb, line 24 def register(id, klass, collector, options = {}) id = id.to_sym if find_with_id(id) raise IDAlreadyUsedError.new("id \"#{id}\" already taken") else configuration = build_configuration(id, klass, collector, options) @configurations << configuration end end
status(id, collector, options = {})
click to toggle source
# File lib/suricate/configuration/widget_configurations_builder.rb, line 20 def status(id, collector, options = {}) register(id, StatusWidget, collector, options) end
Private Instance Methods
build_configuration(id, klass, collector, options)
click to toggle source
# File lib/suricate/configuration/widget_configurations_builder.rb, line 35 def build_configuration(id, klass, collector, options) build_options(id, klass.type, options) WidgetConfiguration.new(id.to_sym, klass, collector, options) end
build_options(id, type, options)
click to toggle source
# File lib/suricate/configuration/widget_configurations_builder.rb, line 40 def build_options(id, type, options) options[:template] = find_widget_template(id, type, options[:template]) if options[:templates] options[:templates].map! do |name| @template_repository.find_widget(name) end end end
find_widget_template(id, type, wanted_template)
click to toggle source
# File lib/suricate/configuration/widget_configurations_builder.rb, line 49 def find_widget_template(id, type, wanted_template) template = nil default_template = type.underscore.sub(/_widget$/, '') template_names = [wanted_template || id.to_s, default_template] template_names.each do |name| begin template = @template_repository.find_widget(name) and break rescue TemplateRepository::TemplateNotFound end end template.render if template end
find_with_id(id)
click to toggle source
# File lib/suricate/configuration/widget_configurations_builder.rb, line 64 def find_with_id(id) @configurations.find { |conf| conf.id == id } end