Class: Mongrel::PageCacheHandler::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/utils.rb

Class Method Summary collapse

Class Method Details

.build_cachetastic_key(request) ⇒ Object



48
49
50
# File 'lib/utils.rb', line 48

def build_cachetastic_key(request)
  File.join(build_path(request), build_file_name(request))
end

.build_directory_path(request, mk_dirs = false) ⇒ Object



26
27
28
29
30
31
# File 'lib/utils.rb', line 26

def build_directory_path(request, mk_dirs = false)
  pcd = ActionController::Base.page_cache_directory
  dir_path = File.join(pcd, build_path(request))
  FileUtils.mkdir_p(dir_path) if mk_dirs
  dir_path
end

.build_file_name(request) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/utils.rb', line 33

def build_file_name(request)
  query_params = build_query_params(request)
  f_name = ""
  query_params.each_pair do |key, value|
    f_name << key.to_s
    f_name << "_"
    f_name << value
    f_name << "-"
  end
  f_name.gsub!(" ", "_")
  f_name.downcase!
  f_name.chop!
  f_name
end

.build_full_file_path(request, mk_dirs = false) ⇒ Object



22
23
24
# File 'lib/utils.rb', line 22

def build_full_file_path(request, mk_dirs = false)
  File.join(build_directory_path(request, mk_dirs), build_file_name(request))
end

.build_path(request) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/utils.rb', line 65

def build_path(request)
  path = request.params[Mongrel::Const::PATH_INFO]# + ActionController::Base.page_cache_extension
  if path == "/" or path.nil? or path == '' # CHANGEME
    path = "/index"
  end
  path
end

.build_query_params(request) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/utils.rb', line 52

def build_query_params(request)
  query_string = request.params["QUERY_STRING"]
  query_params = {:page => "1"}
  unless query_string.blank?
    query_string.split("&").sort.each do |pair|
      pair_values = pair.split("=")
      query_params[pair_values.first.to_sym] = URI.unescape(pair_values.last)
    end
  end
  query_params.delete(:gclid)
  query_params
end

.do_work(request, response) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/utils.rb', line 8

def do_work(request, response)
  if ActionController::Base.perform_caching
    if request.params[Mongrel::Const::REQUEST_METHOD] == "GET"
      case request.params[Mongrel::Const::PATH_INFO]
      when /\.xml$/                              ## CHANGEME
        yield request, response if block_given?  ## CHANGEME
      when /\.[a-zA-Z]*$/
      else
        yield request, response if block_given?  ## CHANGEME
      end
    end
  end
end