Module: AccessLogging::Model::ClassMethods
- Defined in:
- lib/access_logging/model.rb
Instance Method Summary collapse
- #build_from_redis_string(str) ⇒ Object
- #default_verb_for_method(method) ⇒ Object
- #log_request(user, request, opts = {}) ⇒ Object
Instance Method Details
#build_from_redis_string(str) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/access_logging/model.rb', line 64 def build_from_redis_string(str) log = AccessLog.new parts = str.split(REDIS_SEPARATOR, -1) REDIS_ATTRIBUTES.each_with_index do |attribute, i| log.send "#{attribute}=", parts[i] end log end |
#default_verb_for_method(method) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/access_logging/model.rb', line 51 def default_verb_for_method(method) case method.to_s.upcase when 'GET' "viewed" when 'POST' "created" when 'PUT' "updated" when 'DELETE' "deleted" end end |
#log_request(user, request, opts = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/access_logging/model.rb', line 31 def log_request(user, request, opts={}) log = AccessLog.new log.user = user log.ip = request.remote_ip if [:get, :delete].include?(request.method_symbol) log.path = request.fullpath else # Don't log params on POST or PUT requests log.path = request.fullpath.split("?")[0] end log.model = opts[:model] log.verb = opts[:verb] || default_verb_for_method(request.request_method) return if log.model && log.model.new_record? log.save! end |