Class: Heel::Request
- Inherits:
-
Rack::Request
- Object
- Rack::Request
- Heel::Request
- Defined in:
- lib/heel/request.rb
Overview
nothing more than a rack request with some additional methods and overriding where the erros get written
Instance Attribute Summary collapse
-
#root_dir ⇒ Object
readonly
Returns the value of attribute root_dir.
Instance Method Summary collapse
- #base_uri ⇒ Object
- #for_directory? ⇒ Boolean
- #for_file? ⇒ Boolean
-
#forbidden? ⇒ Boolean
a request must be for something that below the root directory.
-
#found? ⇒ Boolean
a request is only good for something that actually exists and is readable.
-
#highlighting? ⇒ Boolean
was the highlighting parameter true or false?.
-
#initialize(env, root_dir) ⇒ Request
constructor
Initialize the request with the environment and the root directory of the request.
-
#request_path ⇒ Object
normalize the request path to the full file path of the request from the
root_dir
. -
#stat ⇒ Object
a stat of the file mentioned in the request path.
Constructor Details
#initialize(env, root_dir) ⇒ Request
Initialize the request with the environment and the root directory of the request
16 17 18 19 |
# File 'lib/heel/request.rb', line 16 def initialize(env, root_dir) super(env) @root_dir = root_dir end |
Instance Attribute Details
#root_dir ⇒ Object (readonly)
Returns the value of attribute root_dir.
12 13 14 |
# File 'lib/heel/request.rb', line 12 def root_dir @root_dir end |
Instance Method Details
#base_uri ⇒ Object
35 36 37 |
# File 'lib/heel/request.rb', line 35 def base_uri @base_uri ||= ::Rack::Utils.unescape(path_info) end |
#for_directory? ⇒ Boolean
52 53 54 |
# File 'lib/heel/request.rb', line 52 def for_directory? stat.directory? end |
#for_file? ⇒ Boolean
56 57 58 |
# File 'lib/heel/request.rb', line 56 def for_file? stat.file? end |
#forbidden? ⇒ Boolean
a request must be for something that below the root directory
42 43 44 |
# File 'lib/heel/request.rb', line 42 def forbidden? request_path.index(root_dir) != 0 end |
#found? ⇒ Boolean
a request is only good for something that actually exists and is readable
48 49 50 |
# File 'lib/heel/request.rb', line 48 def found? File.exist?(request_path) and (stat.directory? or stat.file?) and stat.readable? end |
#highlighting? ⇒ Boolean
was the highlighting parameter true or false?
62 63 64 |
# File 'lib/heel/request.rb', line 62 def highlighting? return !(%w[ off false ].include? self.GET['highlighting'].to_s.downcase) end |
#request_path ⇒ Object
normalize the request path to the full file path of the request from the root_dir
30 31 32 |
# File 'lib/heel/request.rb', line 30 def request_path @request_path ||= ::File.(::File.join(root_dir, ::Rack::Utils.unescape(path_info))) end |
#stat ⇒ Object
a stat of the file mentioned in the request path
23 24 25 |
# File 'lib/heel/request.rb', line 23 def stat @stat ||= ::File.stat(request_path) end |