Module: Scrooge::Optimizations::Columns::InstanceMethods

Defined in:
lib/optimizations/columns/macro.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



116
117
118
119
120
121
122
# File 'lib/optimizations/columns/macro.rb', line 116

def self.included( base )
  base.alias_method_chain :delete, :scrooge
  base.alias_method_chain :destroy, :scrooge
  base.alias_method_chain :respond_to?, :scrooge
  base.alias_method_chain :attributes_from_column_definition, :scrooge
  base.alias_method_chain :becomes, :scrooge
end

Instance Method Details

#_dump(depth) ⇒ Object

Marshal force a full load if needed, and remove any possibility for missing attr flagging



158
159
160
161
162
163
164
165
# File 'lib/optimizations/columns/macro.rb', line 158

def _dump(depth)
  scrooge_fetch_remaining
  scrooge_invalidate_updateable_result_set
  scrooge_dump_flag_this
  str = Marshal.dump(self)
  scrooge_dump_unflag_this
  str
end

#becomes_with_scrooge(klass) ⇒ Object

Augment callsite info for new model class when using STI



146
147
148
149
150
151
152
153
# File 'lib/optimizations/columns/macro.rb', line 146

def becomes_with_scrooge(klass)
  if scrooged?
    self.class.scrooge_callsite(callsite_signature).columns.each do |attrib|
      klass.scrooge_seen_column!(callsite_signature, attrib)
    end
  end
  becomes_without_scrooge(klass)
end

#callsite_signatureObject

Expose this record’s callsite signature



179
180
181
# File 'lib/optimizations/columns/macro.rb', line 179

def callsite_signature
  @attributes.callsite_signature
end

#delete_with_scroogeObject

Delete should fully load all the attributes before the @attributes hash is frozen



132
133
134
135
# File 'lib/optimizations/columns/macro.rb', line 132

def delete_with_scrooge
  scrooge_fetch_remaining
  delete_without_scrooge
end

#destroy_with_scroogeObject

Destroy should fully load all the attributes before the @attributes hash is frozen



139
140
141
142
# File 'lib/optimizations/columns/macro.rb', line 139

def destroy_with_scrooge
  scrooge_fetch_remaining
  destroy_without_scrooge
end

#respond_to_with_scrooge?(symbol, include_private = false) ⇒ Boolean

Enables us to use Marshal.dump inside our _dump method without an infinite loop

Returns:

  • (Boolean)


169
170
171
172
173
174
175
# File 'lib/optimizations/columns/macro.rb', line 169

def respond_to_with_scrooge?(symbol, include_private=false)
  if symbol == :_dump && scrooge_dump_flagged?
    false
  else
    respond_to_without_scrooge?(symbol, include_private)
  end
end

#scrooged?Boolean

Is this instance being handled by scrooge?

Returns:

  • (Boolean)


126
127
128
# File 'lib/optimizations/columns/macro.rb', line 126

def scrooged?
  @attributes.is_a?(ScroogedAttributes)
end