Class: ColumnsTrace::CreatedRecord
- Inherits:
-
Object
- Object
- ColumnsTrace::CreatedRecord
- Defined in:
- lib/columns_trace/created_record.rb
Overview
Class that is used to store metadata about created ActiveRecord records.
Instance Attribute Summary collapse
-
#backtrace ⇒ Array<String>
readonly
Backtrace where the instance was created.
-
#model ⇒ Class
readonly
Model class.
-
#record ⇒ ActiveRecord::Base
readonly
Model instance.
Instance Method Summary collapse
-
#accessed_fields ⇒ Array<String>
Get accessed fields on model instance.
-
#initialize(record, backtrace) ⇒ CreatedRecord
constructor
A new instance of CreatedRecord.
-
#unused_fields ⇒ Array<String>
Get unused fields on model instance.
Constructor Details
#initialize(record, backtrace) ⇒ CreatedRecord
Returns a new instance of CreatedRecord.
21 22 23 24 25 |
# File 'lib/columns_trace/created_record.rb', line 21 def initialize(record, backtrace) @model = record.class @record = record @backtrace = backtrace end |
Instance Attribute Details
#backtrace ⇒ Array<String> (readonly)
Backtrace where the instance was created
19 20 21 |
# File 'lib/columns_trace/created_record.rb', line 19 def backtrace @backtrace end |
#model ⇒ Class (readonly)
Model class
9 10 11 |
# File 'lib/columns_trace/created_record.rb', line 9 def model @model end |
#record ⇒ ActiveRecord::Base (readonly)
Model instance
14 15 16 |
# File 'lib/columns_trace/created_record.rb', line 14 def record @record end |
Instance Method Details
#accessed_fields ⇒ Array<String>
Get accessed fields on model instance
30 31 32 |
# File 'lib/columns_trace/created_record.rb', line 30 def accessed_fields @accessed_fields ||= record.accessed_fields end |
#unused_fields ⇒ Array<String>
Get unused fields on model instance
37 38 39 40 41 42 |
# File 'lib/columns_trace/created_record.rb', line 37 def unused_fields # We need to store this into local variable, because `record.attributes` # will access all attributes. accessed = accessed_fields record.attributes.keys - accessed end |