Class: Rack::Refresh
- Inherits:
-
Object
- Object
- Rack::Refresh
- Defined in:
- lib/rack/refresh.rb,
lib/rack/refresh/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
- #_call(env) ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app, url: nil, interval: 0, **options, &block) ⇒ Refresh
constructor
A new instance of Refresh.
- #refresh(path = nil, interval: nil, url: nil, &matcher) ⇒ Object
Constructor Details
#initialize(app, url: nil, interval: 0, **options, &block) ⇒ Refresh
Returns a new instance of Refresh.
5 6 7 8 9 10 |
# File 'lib/rack/refresh.rb', line 5 def initialize(app, url: nil, interval: 0, **, &block) @app = app @url = url @interval = interval instance_eval(&block) if block_given? end |
Instance Method Details
#_call(env) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/rack/refresh.rb', line 16 def _call(env) response = @app.call(env) route = find_refresh_route_from(env) refresh_for(response, route[:interval], route[:url]) if route response end |
#call(env) ⇒ Object
12 13 14 |
# File 'lib/rack/refresh.rb', line 12 def call(env) dup._call(env) end |
#refresh(path = nil, interval: nil, url: nil, &matcher) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/rack/refresh.rb', line 23 def refresh(path = nil, interval: nil, url: nil, &matcher) current_route = {interval: interval || @interval, url: url || @url} raise ArgumentError, "`:url` must be set in refresh" unless current_route[:url] return unless path || block_given? current_route[:path] = path current_route[:matcher] = matcher routes << current_route end |