Class: ColumnsTrace::CreatedRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/columns_trace/created_record.rb

Overview

Class that is used to store metadata about created ActiveRecord records.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#backtraceArray<String> (readonly)

Backtrace where the instance was created

Returns:

  • (Array<String>)


19
20
21
# File 'lib/columns_trace/created_record.rb', line 19

def backtrace
  @backtrace
end

#modelClass (readonly)

Model class

Returns:

  • (Class)


9
10
11
# File 'lib/columns_trace/created_record.rb', line 9

def model
  @model
end

#recordActiveRecord::Base (readonly)

Model instance

Returns:

  • (ActiveRecord::Base)


14
15
16
# File 'lib/columns_trace/created_record.rb', line 14

def record
  @record
end

Instance Method Details

#accessed_fieldsArray<String>

Get accessed fields on model instance

Returns:

  • (Array<String>)


30
31
32
# File 'lib/columns_trace/created_record.rb', line 30

def accessed_fields
  @accessed_fields ||= record.accessed_fields
end

#unused_fieldsArray<String>

Get unused fields on model instance

Returns:

  • (Array<String>)


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