Class: ProxES::Request
- Inherits:
-
Rack::Request
- Object
- Rack::Request
- ProxES::Request
show all
- Defined in:
- lib/proxes/request.rb,
lib/proxes/request/cat.rb,
lib/proxes/request/bulk.rb,
lib/proxes/request/mget.rb,
lib/proxes/request/root.rb,
lib/proxes/request/index.rb,
lib/proxes/request/multi.rb,
lib/proxes/request/stats.rb,
lib/proxes/request/create.rb,
lib/proxes/request/search.rb,
lib/proxes/request/msearch.rb,
lib/proxes/request/snapshot.rb,
lib/proxes/policies/request/cat_policy.rb,
lib/proxes/policies/request/bulk_policy.rb,
lib/proxes/policies/request/mget_policy.rb,
lib/proxes/policies/request/root_policy.rb,
lib/proxes/policies/request/index_policy.rb,
lib/proxes/policies/request/stats_policy.rb,
lib/proxes/policies/request/create_policy.rb,
lib/proxes/policies/request/search_policy.rb,
lib/proxes/policies/request/msearch_policy.rb,
lib/proxes/policies/request/snapshot_policy.rb
Defined Under Namespace
Classes: Bulk, BulkPolicy, Cat, CatPolicy, Create, CreatePolicy, Index, IndexPolicy, Mget, MgetPolicy, Msearch, MsearchPolicy, Multi, Root, RootPolicy, Search, SearchPolicy, Snapshot, SnapshotPolicy, Stats, StatsPolicy
Constant Summary
collapse
- ID_ENDPOINTS =
%w[_create _explain _mlt _percolate _source _termvector _update].freeze
- WRITE_METHODS =
%w[POST PUT DELETE].freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(env) ⇒ Request
Returns a new instance of Request.
10
11
12
13
14
|
# File 'lib/proxes/request.rb', line 10
def initialize(env)
@started = Time.now.to_f
super
parse
end
|
Class Method Details
.from_env(env) ⇒ Object
75
76
77
78
79
80
81
82
83
84
|
# 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) ⇒ Object
86
87
88
89
90
91
92
93
94
95
|
# 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
|
Instance Method Details
#detail ⇒ Object
54
55
56
57
58
59
|
# 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 ⇒ Object
38
39
40
|
# File 'lib/proxes/request.rb', line 38
def duration
Time.now.to_f - @started
end
|
#endpoint ⇒ Object
16
17
18
|
# File 'lib/proxes/request.rb', line 16
def endpoint
path_parts[0]
end
|
#html? ⇒ Boolean
34
35
36
|
# File 'lib/proxes/request.rb', line 34
def html?
('HTTP_ACCEPT')&.include?('text/html')
end
|
#indices ⇒ Object
Return the indices associated with the request as an array. [] if ‘#indices?` is false
30
31
32
|
# File 'lib/proxes/request.rb', line 30
def indices
[]
end
|
#indices? ⇒ Boolean
Indicate whether or not the request is index specific
25
26
27
|
# File 'lib/proxes/request.rb', line 25
def indices?
false
end
|
#parse ⇒ Object
20
21
22
|
# File 'lib/proxes/request.rb', line 20
def parse
path_parts
end
|
#user ⇒ Object
48
49
50
51
52
|
# File 'lib/proxes/request.rb', line 48
def user
return nil if user_id.nil?
@user ||= Ditty::User[user_id]
end
|
#user_id ⇒ Object
42
43
44
45
46
|
# File 'lib/proxes/request.rb', line 42
def user_id
return session['user_id'] if session['user_id']
env['omniauth.auth']&.uid
end
|