class ProxES::Request
Constants
- ID_ENDPOINTS
- WRITE_METHODS
Public Class Methods
new(env)
click to toggle source
Calls superclass method
# File lib/proxes/request.rb, line 10 def initialize(env) @started = Time.now.to_f super parse end
Private Class Methods
from_env(env)
click to toggle source
# File lib/proxes/request.rb, line 75 def from_env(env) endpoint = path_endpoint(env['REQUEST_PATH']) endpoint_class = endpoint.nil? ? 'index' : endpoint[1..-1] begin require 'proxes/request/' + endpoint_class.downcase Request.const_get(endpoint_class.titlecase).new(env) rescue LoadError new(env) end end
path_endpoint(path)
click to toggle source
# File lib/proxes/request.rb, line 86 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] == '_' && part != '_all' } end
Public Instance Methods
detail()
click to toggle source
# File lib/proxes/request.rb, line 54 def detail detail = "#{request_method.upcase} #{fullpath} (#{self.class.name})" return detail unless indices? "#{detail} #{indices.join(',')}" end
duration()
click to toggle source
# File lib/proxes/request.rb, line 38 def duration Time.now.to_f - @started end
endpoint()
click to toggle source
# File lib/proxes/request.rb, line 16 def endpoint path_parts[0] end
html?()
click to toggle source
# File lib/proxes/request.rb, line 34 def html? get_header('HTTP_ACCEPT')&.include?('text/html') end
indices()
click to toggle source
Return the indices associated with the request as an array. [] if `#indices?` is false
# File lib/proxes/request.rb, line 30 def indices [] end
indices?()
click to toggle source
Indicate whether or not the request is index specific
# File lib/proxes/request.rb, line 25 def indices? false end
parse()
click to toggle source
# File lib/proxes/request.rb, line 20 def parse path_parts end
user()
click to toggle source
# File lib/proxes/request.rb, line 48 def user return nil if user_id.nil? @user ||= Ditty::User[user_id] end
user_id()
click to toggle source
# File lib/proxes/request.rb, line 42 def user_id return session['user_id'] if session['user_id'] env['omniauth.auth']&.uid end
Private Instance Methods
check_part(val)
click to toggle source
# File lib/proxes/request.rb, line 67 def check_part(val) return val if val.nil? return [] if [endpoint, '_all'].include?(val) && !WRITE_METHODS.include?(request_method) val.split(',') end
path_parts()
click to toggle source
# File lib/proxes/request.rb, line 63 def path_parts @path_parts ||= path.split('?')[0][1..-1].split('/') end