class Rack::Prerender
Constants
- RecacheJob
- VERSION
Attributes
app[RW]
constraint[RW]
fetcher[RW]
Public Class Methods
fetch(arg, **options)
click to toggle source
utility methods
# File lib/rack/prerender.rb, line 24 def self.fetch(arg, **options) Fetcher.new(@options.to_h.merge(options)).fetch(arg) end
new(app, options = {})
click to toggle source
# File lib/rack/prerender.rb, line 11 def initialize(app, options = {}) @app = app @constraint = Constraint.new(options) @fetcher = Fetcher.new(options) self.class.instance_variable_set(:@options, options) end
recache_later(url, **options)
click to toggle source
# File lib/rack/prerender.rb, line 32 def self.recache_later(url, **options) # require on demand, so ActiveJob/Sidekiq can come later in load order require_relative 'prerender/recache_job' RecacheJob.perform_later(url, @options.to_h.merge(options)) end
recache_now(url, **options)
click to toggle source
# File lib/rack/prerender.rb, line 28 def self.recache_now(url, **options) Recacher.new(@options.to_h.merge(options)).call(url) end
Public Instance Methods
call(env)
click to toggle source
# File lib/rack/prerender.rb, line 18 def call(env) constraint.matches?(env) && fetcher.call(env) || app.call(env) end