Class: SessionLogger::SessionObserver
- Inherits:
-
ActiveRecord::Observer
- Object
- ActiveRecord::Observer
- SessionLogger::SessionObserver
- Defined in:
- lib/session_logger/session_logging.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
Returns the value of attribute controller.
Class Method Summary collapse
-
.observed_class ⇒ Object
Required to prevent the observer from un-cleverly looking for Session…
Instance Method Summary collapse
- #after(controller) ⇒ Object
-
#before(controller) ⇒ Object
——————————————- Legacy around filter calls.
-
#before_create(record) ⇒ Object
——————————————- ActiveRecord callbacks.
Instance Attribute Details
#controller ⇒ Object
Returns the value of attribute controller.
28 29 30 |
# File 'lib/session_logger/session_logging.rb', line 28 def controller @controller end |
Class Method Details
.observed_class ⇒ Object
Required to prevent the observer from un-cleverly looking for Session…
31 32 33 |
# File 'lib/session_logger/session_logging.rb', line 31 def self.observed_class nil end |
Instance Method Details
#after(controller) ⇒ Object
41 42 43 44 45 |
# File 'lib/session_logger/session_logging.rb', line 41 def after(controller) self.controller = controller # Clean up, so that the controller can be collected after this request self.controller = nil end |
#before(controller) ⇒ Object
——————————————- Legacy around filter calls
36 37 38 39 |
# File 'lib/session_logger/session_logging.rb', line 36 def before(controller) self.controller = controller true # before method from SessionObserver should always return true end |
#before_create(record) ⇒ Object
——————————————- ActiveRecord callbacks
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/session_logger/session_logging.rb', line 48 def before_create(record) return if controller.blank? || controller.session.blank? candidate_columns = record.attributes.select { |attr| attr.starts_with? SessionLogger.model_prefix } candidate_columns.keys.each do |column| column = column.to_s #Only setting if present prevents empty strings from overriding defaults in the schema set_if_present(record, column, controller.session[column]) end #pp controller.session["sl_campaign"] #pp record end |