Class: DevPanel::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/devpanel/stats.rb

Class Method Summary collapse

Class Method Details

.controller_durationObject


50
51
52
# File 'lib/devpanel/stats.rb', line 50

def controller_duration
  (data[:action_controller].duration - stats(:view_runtime)).round(2)
end

.controller_duration_percentObject


58
59
60
# File 'lib/devpanel/stats.rb', line 58

def controller_duration_percent
  ((controller_duration / total_duration) * 100).round(0)
end

.dataObject


34
35
36
# File 'lib/devpanel/stats.rb', line 34

def data
  @@data
end

.defaultsObject


4
5
6
7
8
9
10
11
12
# File 'lib/devpanel/stats.rb', line 4

def defaults
  {
    data: { log: '' },
    visible: 'false',
    left: 0,
    top: 0,
    zindex: 1000
  }
end

.delete_dataObject


70
71
72
# File 'lib/devpanel/stats.rb', line 70

def delete_data
  @@data = {}
end

.invalid_number?(val) ⇒ Boolean

Returns:

  • (Boolean)

42
43
44
# File 'lib/devpanel/stats.rb', line 42

def invalid_number?(val)
  val.class != Fixnum || val.nil?
end

.log(log = nil) ⇒ Object


78
79
80
81
82
83
84
# File 'lib/devpanel/stats.rb', line 78

def log(log = nil)
  return data[:log] unless log
  data[:log] ||= ""
  data[:log] += "<div style='border-bottom: 1px black solid'>"
  data[:log] += CGI::escapeHTML("#{log}")
  data[:log] += "</div>"
end

.method_missing(*arr) ⇒ Object


26
27
28
29
30
31
32
# File 'lib/devpanel/stats.rb', line 26

def method_missing(*arr)
  if [:left, :top, :zindex].include?(arr.first)
    return self.class_variable_get(:"@@#{arr.first}") if arr.size < 2 || (invalid_number?(arr.last.to_i))
    self.class_variable_set(:"@@#{arr.first}", (arr.last || defaults[arr.first]))
    return self.class_variable_get(:"@@#{arr.first}")
  end
end

.set_by_params(params) ⇒ Object


20
21
22
23
24
# File 'lib/devpanel/stats.rb', line 20

def set_by_params(params)
  ['visible', 'left', 'top', 'zindex'].each do |str|
    Stats.send(str, params[str]) if params[str]
  end
end

.set_defaultsObject


14
15
16
17
18
# File 'lib/devpanel/stats.rb', line 14

def set_defaults
  defaults.each_pair do |key, value|
    self.class_variable_set(:"@@#{key}", value)
  end
end

.show?Boolean

Returns:

  • (Boolean)

74
75
76
# File 'lib/devpanel/stats.rb', line 74

def show?
  @@visible == "true"
end

.stats(symbol) ⇒ Object


66
67
68
# File 'lib/devpanel/stats.rb', line 66

def stats(symbol)
  data[:action_controller].payload[symbol]
end

.time(tag = nil) ⇒ Object


86
87
88
89
90
91
# File 'lib/devpanel/stats.rb', line 86

def time(tag = nil)
  start = Time.now
  yield
  time_spent = ((Time.now - start)*1000).round(2)
  self.log("#{tag}: Time Elapsed: #{time_spent}ms")
end

.total_durationObject


46
47
48
# File 'lib/devpanel/stats.rb', line 46

def total_duration
  data[:action_controller].duration.round(2)
end

.view_durationObject


54
55
56
# File 'lib/devpanel/stats.rb', line 54

def view_duration
  stats(:view_runtime).round(2)
end

.view_duration_percentObject


62
63
64
# File 'lib/devpanel/stats.rb', line 62

def view_duration_percent
  ((view_duration / total_duration) * 100).round(0)
end

.visible(val = @@visible) ⇒ Object


38
39
40
# File 'lib/devpanel/stats.rb', line 38

def visible(val = @@visible)
  @@visible = val
end