Class: ActsAsDashboard::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_dashboard/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



5
6
7
# File 'lib/acts_as_dashboard/config.rb', line 5

def initialize
  @widgets = []
end

Instance Attribute Details

#widgetsObject (readonly)

Returns the value of attribute widgets.



3
4
5
# File 'lib/acts_as_dashboard/config.rb', line 3

def widgets
  @widgets
end

Instance Method Details

#add_widget(widget) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
# File 'lib/acts_as_dashboard/config.rb', line 9

def add_widget(widget)
  raise ArgumentError, 'The "widget" argument must be an ActsAsDashboard::Widget.' unless widget.is_a? ActsAsDashboard::Widget
  @widgets.push widget
end

#find_widget(name) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
# File 'lib/acts_as_dashboard/config.rb', line 14

def find_widget(name)
  raise ArgumentError, 'The "name" argument must respond to #to_sym .' unless name.respond_to? :to_sym

  # We specifically use #find_all here so that we can grab the last widget with that name.
  # This allows users to define multiple widgets with the same name, and have only the last
  # be used.
  @widgets.find_all {|w| w.name == name.to_sym}.last
end