Class: Rack::EnvNotifier
- Inherits:
-
Object
- Object
- Rack::EnvNotifier
- Defined in:
- lib/rack/env_notifier.rb,
lib/rack/env_notifier/body_injector.rb,
lib/rack-env-notifier.rb
Defined Under Namespace
Classes: BodyInjector
Constant Summary collapse
- VERSION =
"0.0.3"
Class Method Summary collapse
- .custom_css ⇒ Object
- .custom_css=(css) ⇒ Object
- .message ⇒ Object
- .message=(msg) ⇒ Object
- .notification ⇒ Object
- .notify=(ntf) ⇒ Object
- .notify? ⇒ Boolean
Instance Method Summary collapse
- #_call(env) ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app) ⇒ EnvNotifier
constructor
A new instance of EnvNotifier.
Constructor Details
#initialize(app) ⇒ EnvNotifier
Returns a new instance of EnvNotifier.
47 48 49 |
# File 'lib/rack/env_notifier.rb', line 47 def initialize(app) @app = app end |
Class Method Details
.custom_css ⇒ Object
6 7 8 |
# File 'lib/rack/env_notifier.rb', line 6 def custom_css @custom_css end |
.custom_css=(css) ⇒ Object
10 11 12 |
# File 'lib/rack/env_notifier.rb', line 10 def custom_css=(css) @custom_css = css end |
.message ⇒ Object
14 15 16 |
# File 'lib/rack/env_notifier.rb', line 14 def end |
.message=(msg) ⇒ Object
18 19 20 |
# File 'lib/rack/env_notifier.rb', line 18 def (msg) = msg end |
.notification ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rack/env_notifier.rb', line 22 def notification if @custom_css == true "<!-- Notify Start -->\n<div id=\"env-notifier\" class=\"\#{@message.gsub(/[^a-z]/i, '-').gsub(/--*/, '-').gsub(/-$/, '')}\">\#{@message}</div>\n<!-- Notify End -->\n EOF\n else\n <<-EOF\n<!-- Notify Start -->\n<div id=\"env-notifier\" class=\"\#{@message.gsub(/[^a-z]/i, '-').gsub(/--*/, '-').gsub(/-$/, '')}\" style=\"position: fixed; top: 0; right: 0; left: 0; background: rgba(150, 50, 50, .7); color: #fff; text-align: center; font-size: 16px; font-weight: bold; padding: 2px; z-index: 999999\">\#{@message}</div>\n<!-- Notify End -->\n EOF\n end\nend\n" |
.notify=(ntf) ⇒ Object
42 43 44 |
# File 'lib/rack/env_notifier.rb', line 42 def notify=(ntf) @notify = ntf end |
.notify? ⇒ Boolean
38 39 40 |
# File 'lib/rack/env_notifier.rb', line 38 def notify? @notify end |
Instance Method Details
#_call(env) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rack/env_notifier.rb', line 55 def _call(env) status, headers, body = @app.call(env) # inject headers, notification if status == 200 and EnvNotifier.notify? # inject notification if headers['Content-Type'] =~ %r{text/html} then injector = BodyInjector.new(body, EnvNotifier.notification) injector.inject!(env) # inject header if injector.notification_added headers['X-EnvNotifier'] = EnvNotifier. end headers['Content-Length'] = injector.content_length.to_s [status, headers, injector.new_body] end [status, headers, body] else [status, headers, body] end end |
#call(env) ⇒ Object
51 52 53 |
# File 'lib/rack/env_notifier.rb', line 51 def call(env) dup._call(env) end |