Module: Rack::Pagelime::ClassMethods

Included in:
Rack::Pagelime, Rack::Pagelime
Defined in:
lib/rack/pagelime.rb

Instance Method Summary collapse

Instance Method Details

#disable_processing_for_request(req) ⇒ Object



19
20
21
# File 'lib/rack/pagelime.rb', line 19

def disable_processing_for_request(req)
  req.env[ENV_KEYS[:toggle_processing]] = "off"
end

#enable_processing_for_request(req) ⇒ Object



15
16
17
# File 'lib/rack/pagelime.rb', line 15

def enable_processing_for_request(req)
  req.env[ENV_KEYS[:toggle_processing]] = "on"
end

#handle_publish_callback(req) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/rack/pagelime.rb', line 60

def handle_publish_callback(req)
  
  ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Route for publish callback called!"
  
  ::Pagelime.cache.clear_page(req.params["path"].to_s)
  ::Pagelime.cache.clear_shared
  
  [200, {"Content-Type" => "text/html"}, ["cache cleared"]]
end

#handle_route(req) ⇒ Object

responses



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rack/pagelime.rb', line 34

def handle_route(req)
  if req.get?
    path    = req.path.gsub(/\A\/+|\/+\Z/, "")
    prefix  = ::Pagelime.config.url_path.gsub(/\A\/+|\/+\Z/, "")
    action  = path["#{prefix}/".size..-1].to_s
    
    # hijack response if a pagelime route, otherwise process output if so required
    if path.start_with?("#{prefix}/") || path == prefix
      case action
      # handle publish callback
      when "after_publish_callback"
        resp = handle_publish_callback(req)
      # handle "index"
      when ""
        resp = handle_status_check(req)
      else
        ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Unable to route action! (URL prefix: #{::Pagelime.config.url_path}, Request path: #{req.path})"
      end
    else
      ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Unable to route prefix! (URL prefix: #{::Pagelime.config.url_path}, Request path: #{req.path})"
    end
  end
  
  resp
end

#handle_status_check(req) ⇒ Object



70
71
72
73
74
75
# File 'lib/rack/pagelime.rb', line 70

def handle_status_check(req)
  
  ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Route for index called!"
  
  [200, {"Content-Type" => "text/html"}, ["working"]]
end

#processing_enabled_for_request?(req) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
# File 'lib/rack/pagelime.rb', line 23

def processing_enabled_for_request?(req)
  config_option = ::Pagelime.config.toggle_processing
  config_option = req.env[ENV_KEYS[:toggle_processing]] if config_option == "per_request"
  
  ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Procesing enabled for request? (config: #{::Pagelime.config.toggle_processing}, env: #{req.env[ENV_KEYS[:toggle_processing]]}, evaluated as: #{config_option})"
  
  return config_option == "on"
end