Class: ActionTree::Component::Rack::Request
- Inherits:
-
Rack::Request
- Object
- Rack::Request
- ActionTree::Component::Rack::Request
- Defined in:
- lib/action_tree/components/rack/request.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#accept ⇒ Object
Returns an array of acceptable media types for the response.
- #forwarded? ⇒ Boolean
- #path_info=(value) ⇒ Object
- #preferred_type(*types) ⇒ Object (also: #accept?)
- #route ⇒ Object
Class Method Details
.new(env) ⇒ Object
9 10 11 |
# File 'lib/action_tree/components/rack/request.rb', line 9 def self.new(env) env['actiontree.request'] ||= super end |
Instance Method Details
#accept ⇒ Object
Returns an array of acceptable media types for the response
14 15 16 17 18 19 |
# File 'lib/action_tree/components/rack/request.rb', line 14 def accept @env['actiontree.accept'] ||= begin entries = @env['HTTP_ACCEPT'].to_s.split(',') entries.map { |e| accept_entry(e) }.sort_by(&:last).map(&:first) end end |
#forwarded? ⇒ Boolean
33 34 35 |
# File 'lib/action_tree/components/rack/request.rb', line 33 def forwarded? @env.include? "HTTP_X_FORWARDED_HOST" end |
#path_info=(value) ⇒ Object
44 45 46 47 |
# File 'lib/action_tree/components/rack/request.rb', line 44 def path_info=(value) @route = nil super end |
#preferred_type(*types) ⇒ Object Also known as: accept?
21 22 23 24 25 26 27 28 |
# File 'lib/action_tree/components/rack/request.rb', line 21 def preferred_type(*types) return accept.first if types.empty? types.flatten! accept.detect do |pattern| type = types.detect { |t| File.fnmatch(pattern, t) } return type if type end end |
#route ⇒ Object
37 38 39 40 41 42 |
# File 'lib/action_tree/components/rack/request.rb', line 37 def route @route ||= begin path = Rack::Utils.unescape(path_info) path.empty? ? "/" : path end end |