lib/proxes/request.rb in proxes-0.9.13 vs lib/proxes/request.rb in proxes-0.10.1

- old
+ new

@@ -19,34 +19,45 @@ def parse path_parts end + # Indicate whether or not the request is index specific def indices? false end + # Return the indices associated with the request as an array. [] if `#indices?` is false + def indices + [] + end + def html? - get_header('HTTP_ACCEPT') && get_header('HTTP_ACCEPT').include?('text/html') + get_header('HTTP_ACCEPT')&.include?('text/html') end def duration Time.now.to_f - @started end def user_id - return env['rack.session']['user_id'] if env['rack.session'] - env['omniauth.auth'].uid if env['omniauth.auth'] + return session['user_id'] if session['user_id'] + + env['omniauth.auth']&.uid end def user return nil if user_id.nil? + @user ||= Ditty::User[user_id] end def detail - "#{request_method.upcase} #{fullpath} (#{self.class.name})" + detail = "#{request_method.upcase} #{fullpath} (#{self.class.name})" + return detail unless indices? + + "#{detail} #{indices.join(',')}" end private def path_parts @@ -54,10 +65,11 @@ end def check_part(val) return val if val.nil? return [] if [endpoint, '_all'].include?(val) && !WRITE_METHODS.include?(request_method) + val.split(',') end class << self def from_env(env) @@ -71,14 +83,16 @@ end end def path_endpoint(path) return '_root' if ['', nil, '/'].include? path + path_parts = path[1..-1].split('/') return path_parts[-1] if ID_ENDPOINTS.include? path_parts[-1] return path_parts[-2] if path_parts[-1] == 'count' && path_parts[-2] == '_percolate' return path_parts[-2] if path_parts[-1] == 'scroll' && path_parts[-2] == '_search' - path_parts.find { |part| part[0] == '_' } + + path_parts.find { |part| part[0] == '_' && part != '_all' } end end end end