Class: Censorstrike::Middleware
- Inherits:
-
Object
- Object
- Censorstrike::Middleware
- Defined in:
- lib/censorstrike.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
- #now ⇒ Object
- #render ⇒ Object
Constructor Details
#initialize(app, options = {}) ⇒ Middleware
Returns a new instance of Middleware.
15 16 17 18 |
# File 'lib/censorstrike.rb', line 15 def initialize(app, = {}) @app = app @options = Censorstrike::Middleware..merge() end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
13 14 15 |
# File 'lib/censorstrike.rb', line 13 def app @app end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/censorstrike.rb', line 13 def @options end |
Class Method Details
.default_options ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/censorstrike.rb', line 5 def self. { :begin => Time.at(1326891600).utc, :end => Time.at(1326938400).utc, :file => File.dirname(__FILE__) + '/../message.html' } end |
Instance Method Details
#call(env) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/censorstrike.rb', line 20 def call(env) if now > [:begin] && now < [:end] render else app.call(env) end end |
#now ⇒ Object
28 29 30 |
# File 'lib/censorstrike.rb', line 28 def now Time.now.utc end |
#render ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/censorstrike.rb', line 32 def render response = Rack::Response.new([], 503, 'Content-Type' => 'text/html') body = [:message] ? [:message] : File.read([:file]) body.gsub!("{{footer}}", [:footer] || "") response.write(body) response.finish end |