Class: Rack::Prerender
- Inherits:
-
Object
- Object
- Rack::Prerender
- Defined in:
- lib/rack/prerender.rb,
lib/rack/prerender/fetcher.rb,
lib/rack/prerender/version.rb,
lib/rack/prerender/recacher.rb,
lib/rack/prerender/constraint.rb,
lib/rack/prerender/recache_job.rb
Defined Under Namespace
Classes: Constraint, Fetcher, Recacher
Constant Summary collapse
- VERSION =
'1.6.2.5'
- RecacheJob =
if defined?(::ActiveJob::Base) Class.new(::ActiveJob::Base) elsif defined?(::Sidekiq::Worker) Class.new do include ::Sidekiq::Worker instance_eval { alias perform_later perform_async } end else raise NameError, 'requires ActiveJob or Sidekiq' end.class_eval do def perform(url, ) ::Rack::Prerender::Recacher.new().call(url) end end
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#constraint ⇒ Object
Returns the value of attribute constraint.
-
#fetcher ⇒ Object
Returns the value of attribute fetcher.
Class Method Summary collapse
-
.fetch(arg, **options) ⇒ Object
utility methods.
- .recache_later(url, **options) ⇒ Object
- .recache_now(url, **options) ⇒ Object
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Prerender
constructor
A new instance of Prerender.
Constructor Details
#initialize(app, options = {}) ⇒ Prerender
Returns a new instance of Prerender.
11 12 13 14 15 16 |
# File 'lib/rack/prerender.rb', line 11 def initialize(app, = {}) @app = app @constraint = Constraint.new() @fetcher = Fetcher.new() self.class.instance_variable_set(:@options, ) end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
9 10 11 |
# File 'lib/rack/prerender.rb', line 9 def app @app end |
#constraint ⇒ Object
Returns the value of attribute constraint.
9 10 11 |
# File 'lib/rack/prerender.rb', line 9 def constraint @constraint end |
#fetcher ⇒ Object
Returns the value of attribute fetcher.
9 10 11 |
# File 'lib/rack/prerender.rb', line 9 def fetcher @fetcher end |
Class Method Details
.fetch(arg, **options) ⇒ Object
utility methods
24 25 26 |
# File 'lib/rack/prerender.rb', line 24 def self.fetch(arg, **) Fetcher.new(@options.to_h.merge()).fetch(arg) end |
.recache_later(url, **options) ⇒ Object
32 33 34 35 36 |
# File 'lib/rack/prerender.rb', line 32 def self.recache_later(url, **) # 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()) end |
Instance Method Details
#call(env) ⇒ Object
18 19 20 |
# File 'lib/rack/prerender.rb', line 18 def call(env) constraint.matches?(env) && fetcher.call(env) || app.call(env) end |