Module: Sequel::Plugins::AccessedColumns::InstanceMethods

Defined in:
lib/sequel/plugins/accessed_columns.rb

Instance Method Summary collapse

Instance Method Details

#[](c) ⇒ Object

Record the column access before retrieving the value.



29
30
31
32
# File 'lib/sequel/plugins/accessed_columns.rb', line 29

def [](c)
  (@accessed_columns ||= {})[c] = true unless frozen?
  super
end

#accessed_columnsObject

The columns that have been accessed.



41
42
43
# File 'lib/sequel/plugins/accessed_columns.rb', line 41

def accessed_columns
  @accessed_columns ? @accessed_columns.keys : []
end

#after_saveObject

Clear the accessed columns when saving.



35
36
37
38
# File 'lib/sequel/plugins/accessed_columns.rb', line 35

def after_save
  super
  @accessed_columns = nil
end

#initialize_copy(other) ⇒ Object

Copy the accessed columns when duping and cloning.



46
47
48
49
# File 'lib/sequel/plugins/accessed_columns.rb', line 46

def initialize_copy(other)
  other.instance_variable_set(:@accessed_columns, Hash[@accessed_columns]) if @accessed_columns
  super
end