Module: RailsPerformance::ApplicationHelper
- Included in:
- RailsPerformanceController
- Defined in:
- app/helpers/rails_performance/application_helper.rb
Instance Method Summary collapse
- #active?(section) ⇒ Boolean
- #duraction_alert_class(duration_str) ⇒ Object
- #extract_duration(str) ⇒ Object
- #format_datetime(e) ⇒ Object
- #icon(name) ⇒ Object
- #insert_css_file(file) ⇒ Object
- #insert_js_file(file) ⇒ Object
- #link_to_path(e) ⇒ Object
- #ms(value) ⇒ Object
- #report_name(h) ⇒ Object
- #round_it(value) ⇒ Object
- #short_path(path, length: 60) ⇒ Object
- #status_tag(status) ⇒ Object
Instance Method Details
#active?(section) ⇒ Boolean
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/helpers/rails_performance/application_helper.rb', line 101 def active?(section) case section when :dashboard "is-active" if controller_name == "rails_performance" && action_name == "index" when :crashes "is-active" if controller_name == "rails_performance" && action_name == "crashes" when :requests "is-active" if controller_name == "rails_performance" && action_name == "requests" when :recent "is-active" if controller_name == "rails_performance" && action_name == "recent" when :jobs "is-active" if controller_name == "rails_performance" && action_name == "jobs" end end |
#duraction_alert_class(duration_str) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/helpers/rails_performance/application_helper.rb', line 10 def duraction_alert_class(duration_str) if duration_str.to_s =~ /(\d+.?\d+?)/ duration = $1.to_f if duration >= 500 'has-background-danger has-text-white-bis' elsif duration >= 200 'has-background-warning has-text-black-ter' else 'has-background-success has-text-white-bis' end else 'has-background-light' end end |
#extract_duration(str) ⇒ Object
25 26 27 28 29 30 31 |
# File 'app/helpers/rails_performance/application_helper.rb', line 25 def extract_duration(str) if (str =~ /Duration: (\d+.?\d+?ms)/i) $1 else '-' end end |
#format_datetime(e) ⇒ Object
97 98 99 |
# File 'app/helpers/rails_performance/application_helper.rb', line 97 def format_datetime(e) e.strftime("%Y-%m-%d %H:%M:%S") end |
#icon(name) ⇒ Object
84 85 86 87 |
# File 'app/helpers/rails_performance/application_helper.rb', line 84 def icon(name) # https://www.iconfinder.com/iconsets/vivid raw File.read(File.(File.dirname(__FILE__) + "/../../assets/images/#{name}.svg")) end |
#insert_css_file(file) ⇒ Object
89 90 91 |
# File 'app/helpers/rails_performance/application_helper.rb', line 89 def insert_css_file(file) raw "<style>#{raw File.read File.expand_path(File.dirname(__FILE__) + "/../../views/rails_performance/stylesheets/#{file}")}</style>" end |
#insert_js_file(file) ⇒ Object
93 94 95 |
# File 'app/helpers/rails_performance/application_helper.rb', line 93 def insert_js_file(file) raw "<script>#{raw File.read File.expand_path(File.dirname(__FILE__) + "/../../views/rails_performance/javascripts/#{file}")}</script>" end |
#link_to_path(e) ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/helpers/rails_performance/application_helper.rb', line 44 def link_to_path(e) if e[:method] == 'GET' link_to(short_path(e[:path]), e[:path], target: '_blank') else short_path(e[:path]) end end |
#ms(value) ⇒ Object
33 34 35 36 |
# File 'app/helpers/rails_performance/application_helper.rb', line 33 def ms(value) result = round_it(value) result && result != 0 ? "#{result} ms" : '-' end |
#report_name(h) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/helpers/rails_performance/application_helper.rb', line 52 def report_name(h) h.except(:on).collect do |k, v| next if v.blank? %Q{ <div class="control"> <span class="tags has-addons"> <span class="tag">#{k}</span> <span class="tag is-info is-light">#{v}</span> </span> </div>} end.compact.join.html_safe end |
#round_it(value) ⇒ Object
3 4 5 6 7 8 |
# File 'app/helpers/rails_performance/application_helper.rb', line 3 def round_it(value) return nil unless value return value if value.is_a?(Integer) value.nan? ? nil : value.round(1) end |
#short_path(path, length: 60) ⇒ Object
38 39 40 41 42 |
# File 'app/helpers/rails_performance/application_helper.rb', line 38 def short_path(path, length: 60) content_tag :span, title: path do truncate(path, length: length) end end |
#status_tag(status) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/helpers/rails_performance/application_helper.rb', line 66 def status_tag(status) klass = case status.to_s when /^5/ "tag is-danger" when /^4/ "tag is-warning" when /^3/ "tag is-info" when /^2/ "tag is-success" else nil end content_tag(:span, class: klass) do status end end |