Class: Heel::Request

Inherits:
Rack::Request
  • Object
show all
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

Instance Method Summary collapse

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_dirObject (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_uriObject



35
36
37
# File 'lib/heel/request.rb', line 35

def base_uri
  @base_uri ||= ::Rack::Utils.unescape(path_info)
end

#for_directory?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/heel/request.rb', line 52

def for_directory?
  stat.directory?
end

#for_file?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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_pathObject

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.expand_path(::File.join(root_dir, ::Rack::Utils.unescape(path_info)))
end

#statObject

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