Class: LogRecordBot
- Inherits:
-
Object
- Object
- LogRecordBot
- Defined in:
- app/models/concerns/log_record_bot.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Instance Method Summary collapse
- #add_column(title, content) ⇒ Object
- #add_paragraph(content) ⇒ Object
- #add_section(header, paragraph, level: 3) ⇒ Object
-
#initialize(log_record) ⇒ LogRecordBot
constructor
A new instance of LogRecordBot.
- #link_more(name, url) ⇒ Object
- #set_content ⇒ Object
Constructor Details
#initialize(log_record) ⇒ LogRecordBot
Returns a new instance of LogRecordBot.
4 5 6 7 8 |
# File 'app/models/concerns/log_record_bot.rb', line 4 def initialize(log_record) @log_record = log_record @content = '' set_content end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
2 3 4 |
# File 'app/models/concerns/log_record_bot.rb', line 2 def content @content end |
Instance Method Details
#add_column(title, content) ⇒ Object
29 30 31 |
# File 'app/models/concerns/log_record_bot.rb', line 29 def add_column(title, content) @content << "**#{title}:**#{content}\n" end |
#add_paragraph(content) ⇒ Object
20 21 22 |
# File 'app/models/concerns/log_record_bot.rb', line 20 def add_paragraph(content) @content << "#{content}\n" end |
#add_section(header, paragraph, level: 3) ⇒ Object
24 25 26 27 |
# File 'app/models/concerns/log_record_bot.rb', line 24 def add_section(header, paragraph, level: 3) @content << "#{'#' * level} #{header}\n" @content << "#{paragraph}\n" end |
#link_more(name, url) ⇒ Object
33 34 35 36 37 38 |
# File 'app/models/concerns/log_record_bot.rb', line 33 def link_more(name, url) text = "\n[#{name}](#{url})" truncate_length = 4096 - text.bytesize @content = @content.truncate_bytes(truncate_length) + text end |
#set_content ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'app/models/concerns/log_record_bot.rb', line 10 def set_content @log_record.as_json(only: [:path, :controller_name, :action_name, :params, :session, :headers, :ip]).each do |k, v| add_column @log_record.class.human_attribute_name(k), v unless v.blank? end add_column '用户信息', @log_record.user_info.inspect add_paragraph(@log_record.exception) add_paragraph(@log_record.exception_backtrace[0]) link_more('详细点击', Rails.application.routes.url_for(controller: 'com/panel/errs', action: 'show', id: @log_record.id)) end |