Class: EffectiveLogging::ActiveRecordLogger
- Inherits:
-
Object
- Object
- EffectiveLogging::ActiveRecordLogger
- Defined in:
- lib/effective_logging/active_record_logger.rb
Constant Summary collapse
- BLANK =
"''"
Instance Attribute Summary collapse
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#include_associated ⇒ Object
Returns the value of attribute include_associated.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#object ⇒ Object
Returns the value of attribute object.
-
#options ⇒ Object
Returns the value of attribute options.
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
-
#created! ⇒ Object
after_commit.
-
#destroyed! ⇒ Object
before_destroy.
-
#execute! ⇒ Object
execute! is called when we recurse, otherwise the following methods are best called individually.
-
#initialize(object, options = {}) ⇒ ActiveRecordLogger
constructor
A new instance of ActiveRecordLogger.
-
#updated! ⇒ Object
after_commit.
Constructor Details
#initialize(object, options = {}) ⇒ ActiveRecordLogger
Returns a new instance of ActiveRecordLogger.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/effective_logging/active_record_logger.rb', line 7 def initialize(object, = {}) raise ArgumentError.new('options must be a Hash') unless .kind_of?(Hash) @object = object @resource = Effective::Resource.new(object) @logged = false # If work was done @logger = .delete(:logger) || object @depth = .delete(:depth) || 0 @include_associated = .fetch(:include_associated, true) = raise ArgumentError.new('logger must respond to logged_changes') unless @logger.respond_to?(:logged_changes) end |
Instance Attribute Details
#depth ⇒ Object
Returns the value of attribute depth.
3 4 5 |
# File 'lib/effective_logging/active_record_logger.rb', line 3 def depth @depth end |
#include_associated ⇒ Object
Returns the value of attribute include_associated.
3 4 5 |
# File 'lib/effective_logging/active_record_logger.rb', line 3 def include_associated @include_associated end |
#logger ⇒ Object
Returns the value of attribute logger.
3 4 5 |
# File 'lib/effective_logging/active_record_logger.rb', line 3 def logger @logger end |
#object ⇒ Object
Returns the value of attribute object.
3 4 5 |
# File 'lib/effective_logging/active_record_logger.rb', line 3 def object @object end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/effective_logging/active_record_logger.rb', line 3 def end |
#resource ⇒ Object
Returns the value of attribute resource.
3 4 5 |
# File 'lib/effective_logging/active_record_logger.rb', line 3 def resource @resource end |
Instance Method Details
#created! ⇒ Object
after_commit
43 44 45 |
# File 'lib/effective_logging/active_record_logger.rb', line 43 def created! log('Created', details: applicable(resource.instance_attributes(include_associated: include_associated))) end |
#destroyed! ⇒ Object
before_destroy
38 39 40 |
# File 'lib/effective_logging/active_record_logger.rb', line 38 def destroyed! log('Deleted') end |
#execute! ⇒ Object
execute! is called when we recurse, otherwise the following methods are best called individually
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/effective_logging/active_record_logger.rb', line 23 def execute! if object.new_record? created! elsif object.marked_for_destruction? destroyed! else changed! end log_nested_resources! if include_associated @logged end |
#updated! ⇒ Object
after_commit
48 49 50 |
# File 'lib/effective_logging/active_record_logger.rb', line 48 def updated! log('Updated', details: applicable(resource.instance_attributes(include_associated: include_associated))) end |