Class: Rack::ActiveRecordReconnector
- Inherits:
-
Object
- Object
- Rack::ActiveRecordReconnector
- Defined in:
- lib/rack/active_record_reconnector.rb,
lib/rack/active_record_reconnector/version.rb
Constant Summary collapse
- VERSION =
"0.1.2"
Instance Attribute Summary collapse
-
#log_level ⇒ Object
readonly
Returns the value of attribute log_level.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#call(env) ⇒ Object
- param
-
Hash env [return] Rack::Response.
-
#detect_log_level(options = {}) ⇒ Object
- param
-
Hash options [return] Symbol or nil.
-
#initialize(app, options = {}) ⇒ ActiveRecordReconnector
constructor
- param
-
Rack::Application app [param] Hash options.
Constructor Details
#initialize(app, options = {}) ⇒ ActiveRecordReconnector
- param
-
Rack::Application app
- param
-
Hash options
9 10 11 12 13 14 15 |
# File 'lib/rack/active_record_reconnector.rb', line 9 def initialize(app, = {}) @app = app @log_level ||= detect_log_level() if .has_key?(:logger) && !@log_level.nil? @logger ||= [:logger] end end |
Instance Attribute Details
#log_level ⇒ Object (readonly)
Returns the value of attribute log_level.
16 17 18 |
# File 'lib/rack/active_record_reconnector.rb', line 16 def log_level @log_level end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
16 17 18 |
# File 'lib/rack/active_record_reconnector.rb', line 16 def logger @logger end |
Instance Method Details
#call(env) ⇒ Object
- param
-
Hash env
- return
-
Rack::Response
36 37 38 39 40 41 42 43 44 |
# File 'lib/rack/active_record_reconnector.rb', line 36 def call(env) begin @app.call(env) rescue Exception => e logger.send(log_level, "ActiveRecord reconnect ! by #{e.inspect} from #{e.backtrace.first}") if logger ::ActiveRecord::Base.connection.reconnect! raise e end end |
#detect_log_level(options = {}) ⇒ Object
- param
-
Hash options
- return
-
Symbol or nil
22 23 24 25 26 27 28 29 30 |
# File 'lib/rack/active_record_reconnector.rb', line 22 def detect_log_level( = {}) if .has_key? :log_level [:log_level] else if .has_key? :debug [:debug] ? :debug : nil end end end |