Module: ExpressAnalytics::DefaultLogger::InstanceMethods
- Defined in:
- lib/express_analytics/default_logger.rb
Instance Method Summary collapse
- #action_for_log ⇒ Object
- #create_log_entry! ⇒ Object
- #entity_for_log ⇒ Object
- #notes_for_log ⇒ Object
Instance Method Details
#action_for_log ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/express_analytics/default_logger.rb', line 52 def action_for_log # ExpressAnalytics::LogEntriesController#show becomes # express_analytics/log_entries_controller#show # show log entry is_plural = %w(list index).include?(request.params[:action]) object_name = self.class.to_s.demodulize.underscore.titleize object_name.gsub!(/ Controller/, '') object_name = is_plural ? object_name : object_name.singularize verb = is_plural ? 'view' : request.params[:action] "#{verb} #{object_name}" end |
#create_log_entry! ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/express_analytics/default_logger.rb', line 25 def create_log_entry! geo_data = begin ExpressGeoip.lookup(request.remote_ip) rescue => e {} end entity = entity_for_log entry_data = { action: action_for_log, username: current_user.try(:email), ip_address: request.ip, user_agent: request.user_agent, entity_type: entity.try(:class).try(:to_s), entity_id: entity.try(:id), notes: notes_for_log } if !!request.user_agent.match(/Pingdom/) # do nothing else ExpressAnalytics::LogEntry.create(entry_data.merge(geo_data)) end end |
#entity_for_log ⇒ Object
65 66 67 |
# File 'lib/express_analytics/default_logger.rb', line 65 def entity_for_log self.respond_to?(:resource) ? resource : nil end |
#notes_for_log ⇒ Object
69 70 71 |
# File 'lib/express_analytics/default_logger.rb', line 69 def notes_for_log request.path # override to add notes end |