Module: ArJdbc::Util::SerializedAttributes
- Defined in:
- lib/arjdbc/util/serialized_attributes.rb
Overview
Gets included into ActiveRecord::Base to support sending LOB values
in a separate update SQL statement for DB adapters that need this.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#update_lob_columns ⇒ Object
protected.
Class Method Details
.dump_column_value(record, column) ⇒ Object
34 35 36 37 |
# File 'lib/arjdbc/util/serialized_attributes.rb', line 34 def self.dump_column_value(record, column) value = record[ column.name.to_s ] column.cast_type.type_cast_for_database(value) end |
.setup(lob_type = nil, after_save_alias = nil) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/arjdbc/util/serialized_attributes.rb', line 59 def self.setup(lob_type = nil, after_save_alias = nil) ActiveRecord::Base.send :include, self # include SerializedAttributes ActiveRecord::Base.lob_type = lob_type unless lob_type.nil? if after_save_alias ActiveRecord::Base.class_eval do alias_method after_save_alias, 'update_lob_columns' end ActiveRecord::Base.after_save after_save_alias else ActiveRecord::Base.after_save 'update_lob_columns' end end |
Instance Method Details
#update_lob_columns ⇒ Object
protected
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/arjdbc/util/serialized_attributes.rb', line 9 def update_lob_columns klass = self.class return unless type = klass.lob_type # e.g. /blob/i connection = klass.connection if connection.respond_to?(:update_lob_values?) return false unless connection.update_lob_values? end klass.columns.each do |column| next if column.sql_type !~ type next if ( value = dump_column_value(column) ).nil? if connection.respond_to?(:update_lob_value?) next unless connection.update_lob_value?(value, column) end connection.update_lob_value(self, column, value) end end |