Module: RailsPerformanceHelper
- Defined in:
- app/helpers/rails_performance_helper.rb
Instance Method Summary collapse
- #active?(section) ⇒ Boolean
- #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
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/helpers/rails_performance_helper.rb', line 75 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" end end |
#format_datetime(e) ⇒ Object
71 72 73 |
# File 'app/helpers/rails_performance_helper.rb', line 71 def format_datetime(e) e.strftime("%Y-%m-%d %H:%M:%S") end |
#icon(name) ⇒ Object
58 59 60 61 |
# File 'app/helpers/rails_performance_helper.rb', line 58 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
63 64 65 |
# File 'app/helpers/rails_performance_helper.rb', line 63 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
67 68 69 |
# File 'app/helpers/rails_performance_helper.rb', line 67 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
20 21 22 23 24 25 26 |
# File 'app/helpers/rails_performance_helper.rb', line 20 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
9 10 11 12 |
# File 'app/helpers/rails_performance_helper.rb', line 9 def ms(value) result = round_it(value) result && result != 0 ? "#{result} ms" : '-' end |
#report_name(h) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/helpers/rails_performance_helper.rb', line 28 def report_name(h) h.except(:on).collect do |k, v| %Q{ <div class="control"> <span class="tags has-addons"> <span class="tag">#{k}</span> <span class="tag is-success">#{v}</span> </span> </div>} end.join.html_safe end |
#round_it(value) ⇒ Object
2 3 4 5 6 7 |
# File 'app/helpers/rails_performance_helper.rb', line 2 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
14 15 16 17 18 |
# File 'app/helpers/rails_performance_helper.rb', line 14 def short_path(path, length: 60) content_tag :span, title: path do truncate(path, length: length) end end |
#status_tag(status) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/helpers/rails_performance_helper.rb', line 40 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 |