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.



31
32
33
34
# File 'lib/sequel/plugins/accessed_columns.rb', line 31

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

#accessed_columnsObject

The columns that have been accessed.



43
44
45
# File 'lib/sequel/plugins/accessed_columns.rb', line 43

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

#after_saveObject

Clear the accessed columns when saving.



37
38
39
40
# File 'lib/sequel/plugins/accessed_columns.rb', line 37

def after_save
  super
  @accessed_columns = nil
end

#initialize_copy(other) ⇒ Object

Copy the accessed columns when duping and cloning.



48
49
50
51
# File 'lib/sequel/plugins/accessed_columns.rb', line 48

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