Module: ArSync::ModelBase::ClassMethods::WriteHook

Defined in:
lib/ar_sync/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#_initialize_sync_info_before_mutationObject



144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/ar_sync/class_methods.rb', line 144

def _initialize_sync_info_before_mutation
  return unless defined? @_initialized
  if new_record?
    @_sync_watch_values_before_mutation ||= {}
    @_sync_parents_info_before_mutation ||= {}
    @_sync_belongs_to_info_before_mutation ||= {}
  else
    self.class.default_scoped.scoping do
      @_sync_watch_values_before_mutation ||= _sync_current_watch_values
      @_sync_parents_info_before_mutation ||= _sync_current_parents_info
      @_sync_belongs_to_info_before_mutation ||= _sync_current_belongs_to_info
    end
  end
end

#_write_attribute(attr_name, value) ⇒ Object



158
159
160
161
# File 'lib/ar_sync/class_methods.rb', line 158

def _write_attribute(attr_name, value)
  _initialize_sync_info_before_mutation
  super attr_name, value
end

#write_attribute(attr_name, value) ⇒ Object



162
163
164
165
# File 'lib/ar_sync/class_methods.rb', line 162

def write_attribute(attr_name, value)
  _initialize_sync_info_before_mutation
  super attr_name, value
end