Module: RailsVitals::ApplicationHelper
- Defined in:
- app/helpers/rails_vitals/application_helper.rb
Constant Summary collapse
- COLOR_GREEN =
"#276749"- COLOR_BLUE =
"#2b6cb0"- COLOR_AMBER =
"#b7791f"- COLOR_RED =
"#c53030"- COLOR_DARK_RED =
"#742a2a"- COLOR_GRAY =
"#4a5568"- COLOR_NEUTRAL =
"#a0aec0"- COLOR_LIGHT_RED =
"#fc8181"- COLOR_ORANGE =
"#f6ad55"- COLOR_LIGHT_GREEN =
"#68d391"
Class Method Summary collapse
-
.score_color_for(color) ⇒ Object
Module-level helper so plain Ruby classes (e.g. PanelRenderer) can resolve a score color without needing a helper instance.
Instance Method Summary collapse
-
#badge_class(color) ⇒ Object
Returns the full badge CSS class string for a score color label.
- #callback_color(kind) ⇒ Object
- #cost_color(cost) ⇒ Object
- #format_ms(value) ⇒ Object
- #n1_heat_color(pct) ⇒ Object
-
#percentage(count, total) ⇒ Object
Calculates a percentage of count over total, returning 0 when total is zero.
- #query_heat_color(count) ⇒ Object
-
#risk_color(risk) ⇒ Object
Returns a hex color for a DNA risk level symbol (:healthy, :neutral, :warning, :danger).
- #rows_color(rows) ⇒ Object
- #score_color(color) ⇒ Object
- #score_label_to_color(score) ⇒ Object
-
#score_text_color(score) ⇒ Object
Returns a readable hex text color for a numeric health score (0-100).
- #time_color(ms) ⇒ Object
- #time_heat_color(ms) ⇒ Object
Class Method Details
.score_color_for(color) ⇒ Object
Module-level helper so plain Ruby classes (e.g. PanelRenderer) can resolve a score color without needing a helper instance.
16 17 18 19 20 21 22 23 |
# File 'app/helpers/rails_vitals/application_helper.rb', line 16 def self.score_color_for(color) case color when "green" then COLOR_GREEN when "blue" then COLOR_BLUE when "amber" then COLOR_AMBER else COLOR_RED end end |
Instance Method Details
#badge_class(color) ⇒ Object
Returns the full badge CSS class string for a score color label.
118 119 120 |
# File 'app/helpers/rails_vitals/application_helper.rb', line 118 def badge_class(color) "badge badge-#{color}" end |
#callback_color(kind) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'app/helpers/rails_vitals/application_helper.rb', line 38 def callback_color(kind) case kind.to_sym when :validation, :save then COLOR_BLUE when :create, :update then COLOR_GREEN when :destroy then COLOR_RED when :commit then COLOR_AMBER when :rollback then COLOR_DARK_RED else COLOR_GRAY end end |
#cost_color(cost) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'app/helpers/rails_vitals/application_helper.rb', line 70 def cost_color(cost) return COLOR_NEUTRAL unless cost cost = cost.to_f if cost < 100 then COLOR_LIGHT_GREEN elsif cost < 1000 then COLOR_ORANGE else COLOR_LIGHT_RED end end |
#format_ms(value) ⇒ Object
122 123 124 125 126 |
# File 'app/helpers/rails_vitals/application_helper.rb', line 122 def format_ms(value) return "0ms" unless value "#{value.to_f.round(1)}ms" end |
#n1_heat_color(pct) ⇒ Object
63 64 65 66 67 68 |
# File 'app/helpers/rails_vitals/application_helper.rb', line 63 def n1_heat_color(pct) if pct >= 75 then COLOR_LIGHT_RED elsif pct >= 25 then COLOR_ORANGE else COLOR_LIGHT_GREEN end end |
#percentage(count, total) ⇒ Object
Calculates a percentage of count over total, returning 0 when total is zero.
129 130 131 |
# File 'app/helpers/rails_vitals/application_helper.rb', line 129 def percentage(count, total) total.to_f > 0 ? ((count.to_f / total) * 100).round(1) : 0 end |
#query_heat_color(count) ⇒ Object
49 50 51 52 53 54 |
# File 'app/helpers/rails_vitals/application_helper.rb', line 49 def query_heat_color(count) if count >= 25 then COLOR_LIGHT_RED elsif count >= 10 then COLOR_ORANGE else COLOR_LIGHT_GREEN end end |
#risk_color(risk) ⇒ Object
Returns a hex color for a DNA risk level symbol (:healthy, :neutral, :warning, :danger)
98 99 100 101 102 103 104 105 |
# File 'app/helpers/rails_vitals/application_helper.rb', line 98 def risk_color(risk) { healthy: COLOR_LIGHT_GREEN, neutral: COLOR_NEUTRAL, warning: COLOR_ORANGE, danger: COLOR_LIGHT_RED }[risk.to_sym] || COLOR_NEUTRAL end |
#rows_color(rows) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'app/helpers/rails_vitals/application_helper.rb', line 88 def rows_color(rows) return COLOR_NEUTRAL unless rows rows = rows.to_i if rows < 1_000 then COLOR_LIGHT_GREEN elsif rows < 10_000 then COLOR_ORANGE else COLOR_LIGHT_RED end end |
#score_color(color) ⇒ Object
25 26 27 |
# File 'app/helpers/rails_vitals/application_helper.rb', line 25 def score_color(color) RailsVitals::ApplicationHelper.score_color_for(color) end |
#score_label_to_color(score) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'app/helpers/rails_vitals/application_helper.rb', line 29 def score_label_to_color(score) case score when 90..100 then "healthy" when 70..89 then "acceptable" when 50..69 then "warning" else "critical" end end |
#score_text_color(score) ⇒ Object
Returns a readable hex text color for a numeric health score (0-100)
108 109 110 111 112 113 114 115 |
# File 'app/helpers/rails_vitals/application_helper.rb', line 108 def score_text_color(score) case score.to_i when 90..100 then COLOR_LIGHT_GREEN when 70..89 then "#4299e1" when 50..69 then COLOR_ORANGE else COLOR_LIGHT_RED end end |
#time_color(ms) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'app/helpers/rails_vitals/application_helper.rb', line 79 def time_color(ms) return COLOR_NEUTRAL unless ms ms = ms.to_f if ms < 10 then COLOR_LIGHT_GREEN elsif ms < 100 then COLOR_ORANGE else COLOR_LIGHT_RED end end |
#time_heat_color(ms) ⇒ Object
56 57 58 59 60 61 |
# File 'app/helpers/rails_vitals/application_helper.rb', line 56 def time_heat_color(ms) if ms >= 500 then COLOR_LIGHT_RED elsif ms >= 100 then COLOR_ORANGE else COLOR_LIGHT_GREEN end end |