Class: Gecko::Widget
- Inherits:
-
Object
show all
- Defined in:
- lib/gecko/widget.rb,
lib/gecko/graph/pie.rb,
lib/gecko/graph/line.rb,
lib/gecko/widget/rag.rb,
lib/gecko/widget/text.rb,
lib/gecko/graph/funnel.rb,
lib/gecko/graph/geckometer.rb,
lib/gecko/widget/rag_columns.rb,
lib/gecko/widget/number_secondary_stat.rb
Defined Under Namespace
Classes: Funnel, Geckometer, Line, NumberSecondaryStat, Pie, Rag, RagColumns, Text
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*keys, &block) ⇒ Widget
Returns a new instance of Widget.
5
6
7
8
9
10
|
# File 'lib/gecko/widget.rb', line 5
def initialize(*keys, &block)
self.keys = *keys
@on_update = nil
block.call(self) if block
raise ArgumentError, "1 or more widget keys are required" if self.keys.empty?
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3
4
5
|
# File 'lib/gecko/widget.rb', line 3
def data
@data
end
|
#keys ⇒ Object
Returns the value of attribute keys.
3
4
5
|
# File 'lib/gecko/widget.rb', line 3
def keys
@keys
end
|
Instance Method Details
#config(&block) ⇒ Object
44
45
46
47
|
# File 'lib/gecko/widget.rb', line 44
def config(&block)
block.call(self)
self
end
|
#config!(&block) ⇒ Object
49
50
51
52
|
# File 'lib/gecko/widget.rb', line 49
def config!(&block)
self.config(&block).update
self
end
|
#data_payload ⇒ Object
54
55
56
|
# File 'lib/gecko/widget.rb', line 54
def data_payload
{}
end
|
#on_update(&block) ⇒ Object
16
17
18
19
|
# File 'lib/gecko/widget.rb', line 16
def on_update(&block)
@permanent_on_update = block
self
end
|
#payload ⇒ Object
58
59
60
61
62
63
|
# File 'lib/gecko/widget.rb', line 58
def payload
{
:api_key => Gecko.config.api_key,
:data => self.data_payload
}
end
|
#push_requests(&each_result) ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/gecko/widget.rb', line 35
def push_requests(&each_result)
self.keys.map do |key|
http = Gecko::Http.new
push_result = http.post(self.push_url(key), self.payload)
each_result.call(push_result, key) if each_result
push_result
end
end
|
#push_url(key) ⇒ Object
21
22
23
|
# File 'lib/gecko/widget.rb', line 21
def push_url(key)
Gecko.config.api_push_url.gsub(/:widget_key/, key)
end
|
#update(&on_update) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/gecko/widget.rb', line 25
def update(&on_update)
self.push_requests do |push_result, key|
push_result.on_complete do |*args|
args << key
@permanent_on_update.call(*args) if @permanent_on_update.respond_to?(:call)
on_update.call(*args) if on_update
end
end
end
|