Class: Toolbox::WidgetList

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_name, widgets, type) ⇒ WidgetList

Returns a new instance of WidgetList.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/toolbox/config.rb', line 7

def initialize model_name, widgets, type
  @widgets = []
  last = nil
  h = nil
  widgets.each do |widget|
    h = { :name => last, :model_name => model_name}
    if widget.is_a? Hash
      raise 'Before an option hash there must be a widget name (string or symbol)' unless last
      raise 'The item before a option hash must be a string or a symbol' unless last.is_a?(String) || last.is_a?(Symbol)
      h.merge! widget
    end
    @widgets << type.new(h) if last && !last.is_a?(Hash)
    last = widget
  end
  # add the last field, if it's a symbol
  if last && !last.is_a?(Hash)
    h = { :name => last, :model_name => model_name}
    @widgets << type.new(h)
  end
end

Instance Attribute Details

#widgetsObject (readonly)

Returns the value of attribute widgets.



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

def widgets
  @widgets
end