Module: ActiveRecord::CheckArrayBeforeUpdate
- Includes:
- ActiveSupport::Concern
- Defined in:
- lib/ar_jdbc_pg_array/allways_save.rb,
lib/ar_jdbc_pg_array/allways_save.rb,
lib/ar_jdbc_pg_array/allways_save.rb
Class Method Summary collapse
Instance Method Summary collapse
- #_read_attribute(attr_name) ⇒ Object
- #mark_arrays_for_update ⇒ Object
- #update ⇒ Object
- #update_with_check_array ⇒ Object
Class Method Details
.included(base) ⇒ Object
11 12 13 14 |
# File 'lib/ar_jdbc_pg_array/allways_save.rb', line 11 def self.included(base) base.alias_method_chain :update, :check_array base.send(:alias_method, :_read_attribute, :read_attribute) end |
Instance Method Details
#_read_attribute(attr_name) ⇒ Object
26 27 28 |
# File 'lib/ar_jdbc_pg_array/allways_save.rb', line 26 def _read_attribute(attr_name) column_for_attribute(attr_name).type_cast(@attributes[attr_name]) end |
#mark_arrays_for_update ⇒ Object
3 4 5 6 7 |
# File 'lib/ar_jdbc_pg_array/allways_save.rb', line 3 def mark_arrays_for_update @attributes_cache.each do |name, value| attribute_will_change!(name) if Array === value && _read_attribute(name) != value end end |
#update ⇒ Object
31 32 33 34 |
# File 'lib/ar_jdbc_pg_array/allways_save.rb', line 31 def update(*) mark_arrays_for_update super end |
#update_with_check_array ⇒ Object
16 17 18 19 |
# File 'lib/ar_jdbc_pg_array/allways_save.rb', line 16 def update_with_check_array mark_arrays_for_update update_without_check_array end |