Class: DevPanel::Stats

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

Constant Summary collapse

@@visible =
"false"
@@left =
0
@@top =
0

Class Method Summary collapse

Class Method Details

.controller_durationObject



24
25
26
# File 'lib/devpanel/stats.rb', line 24

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

.controller_duration_percentObject



32
33
34
# File 'lib/devpanel/stats.rb', line 32

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

.dataObject



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

def self.data
  @@data ||= { log: "" }
end

.delete_dataObject



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

def self.delete_data
  @@data = {}
end

.left(val = @@left) ⇒ Object



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

def self.left(val = @@left)
  return @@left if val.class != Fixnum && val.empty?
  @@left = val || 0
end

.log(log) ⇒ Object



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

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

.set_by_params(params) ⇒ Object



9
10
11
12
13
14
# File 'lib/devpanel/stats.rb', line 9

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

.show?Boolean



68
69
70
# File 'lib/devpanel/stats.rb', line 68

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

.stats(symbol) ⇒ Object



40
41
42
# File 'lib/devpanel/stats.rb', line 40

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

.timeObject



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

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

.top(val = @@top) ⇒ Object



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

def self.top(val = @@top)
  return @@top if val.class != Fixnum && val.empty?
  @@top = val
end

.total_durationObject



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

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

.view_durationObject



28
29
30
# File 'lib/devpanel/stats.rb', line 28

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

.view_duration_percentObject



36
37
38
# File 'lib/devpanel/stats.rb', line 36

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

.visible(val = @@visible) ⇒ Object



64
65
66
# File 'lib/devpanel/stats.rb', line 64

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

.zindex(val = @@zindex) ⇒ Object



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

def self.zindex(val = @@zindex)
  return @@zindex if val.class != Fixnum && val.empty?
  @@zindex = val || 1000
end