Class: Appboard::DashboardSetup::Dashboard
- Inherits:
-
Object
- Object
- Appboard::DashboardSetup::Dashboard
- Defined in:
- lib/appboard/dashboardsetup.rb
Overview
Defines dashboard
Instance Method Summary collapse
- #get_widgets ⇒ Object
- #has(name) ⇒ Object
-
#initialize(name, &block) ⇒ Dashboard
constructor
A new instance of Dashboard.
- #name ⇒ Object
- #to_json(*a) ⇒ Object
- #uid(value = nil) ⇒ Object
-
#widget(widget_name) ⇒ Object
Define a widget.
- #widgets ⇒ Object
- #width(value = nil) ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Dashboard
Returns a new instance of Dashboard.
6 7 8 9 10 11 12 |
# File 'lib/appboard/dashboardsetup.rb', line 6 def initialize(name, &block) @widgets = {} @width = 5 @name = name instance_eval(&block) end |
Instance Method Details
#get_widgets ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/appboard/dashboardsetup.rb', line 55 def = [] @widgets.each do |name, | << end end |
#has(name) ⇒ Object
65 66 67 |
# File 'lib/appboard/dashboardsetup.rb', line 65 def has(name) true if @widgets[name] end |
#name ⇒ Object
18 19 20 |
# File 'lib/appboard/dashboardsetup.rb', line 18 def name @name end |
#to_json(*a) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/appboard/dashboardsetup.rb', line 69 def to_json(*a) = [] @widgets.each do |name, | << end { :name => @name, :width => @width, :widgets => }.to_json(*a) end |
#uid(value = nil) ⇒ Object
27 28 29 30 |
# File 'lib/appboard/dashboardsetup.rb', line 27 def uid(value = nil) @uid = value unless value.nil? @uid end |
#widget(widget_name) ⇒ Object
Define a widget. May be called inside push loop or separately
widget(‘name’)
type "..."
size "..."
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/appboard/dashboardsetup.rb', line 39 def () if block_given? block = Proc.new = Widget.new(, &block) raise ArgumentError, "Widget with name '#{.to_s}' is already defined" if @widgets[.to_s] @widgets[.to_s] = else = @widgets[.to_s] raise ArgumentError, "Widget is not defined, to define new widget you must supply a block as the last argument" if .nil? end end |
#widgets ⇒ Object
14 15 16 |
# File 'lib/appboard/dashboardsetup.rb', line 14 def @widgets end |
#width(value = nil) ⇒ Object
22 23 24 25 |
# File 'lib/appboard/dashboardsetup.rb', line 22 def width(value = nil) @width = value unless value.nil? @width end |