Class: Mentawai::Handler::RequestURL

Inherits:
Object
  • Object
show all
Defined in:
lib/mentawai/handler/menta_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context_path, context_path_dir, url, default_page) ⇒ RequestURL

Returns a new instance of RequestURL.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/mentawai/handler/menta_handler.rb', line 118

def initialize(context_path, context_path_dir, url, default_page)

  # Construct file path for the URL...
  if context_path == '/'
    @url_file_path = '.' + context_path_dir + url
    @url_with_context_dir = context_path_dir + url
    @url_without_context_dir = url
  else
    @url_file_path = '.' + url
    @url_with_context_dir = url
    @url_without_context_dir = url.sub(/#{context_path_dir}/, "")
    @url_without_context_dir = '/' if @url_without_context_dir == ""
  end
  
  @is_dir = File.directory?(@url_file_path)
  
  # Check if we need to append the default_page
  if @is_dir
    url_file_path_with_default_page = append_filename(@url_file_path, default_page)
    if File.exists?(url_file_path_with_default_page)
      @is_dir = false
      @url_without_context_dir = append_filename(@url_without_context_dir, default_page)
      @url_with_context_dir = append_filename(@url_with_context_dir, default_page)
      @url_file_path = url_file_path_with_default_page
    end
  end
  
  # Check if this is a forbidden URL
  if @url_with_context_dir =~ /^#{context_path_dir}\/WEB-INF/
    @forbidden = true
  else
    @forbidden = false
  end
end

Instance Attribute Details

#url_file_pathObject (readonly)

Returns the value of attribute url_file_path.



153
154
155
# File 'lib/mentawai/handler/menta_handler.rb', line 153

def url_file_path
  @url_file_path
end

#url_with_context_dirObject (readonly)

Returns the value of attribute url_with_context_dir.



153
154
155
# File 'lib/mentawai/handler/menta_handler.rb', line 153

def url_with_context_dir
  @url_with_context_dir
end

#url_without_context_dirObject (readonly)

Returns the value of attribute url_without_context_dir.



153
154
155
# File 'lib/mentawai/handler/menta_handler.rb', line 153

def url_without_context_dir
  @url_without_context_dir
end

Instance Method Details

#forbidden?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/mentawai/handler/menta_handler.rb', line 159

def forbidden?
  @forbidden
end

#is_dir?Boolean

Returns:

  • (Boolean)


155
156
157
# File 'lib/mentawai/handler/menta_handler.rb', line 155

def is_dir?
  @is_dir
end

#to_sObject



163
164
165
# File 'lib/mentawai/handler/menta_handler.rb', line 163

def to_s
  "RequestURL: without=#{url_without_context_dir} with=#{url_with_context_dir} path=#{url_file_path} forbidden=#{forbidden?} is_dir=#{is_dir?}"
end