Module: Authentasaurus::Arel::ActsAsAuthenticatable::InstanceMethods

Defined in:
lib/authentasaurus/arel/acts_as_authenticatable.rb

Instance Method Summary collapse

Instance Method Details

#syncObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/authentasaurus/arel/acts_as_authenticatable.rb', line 51

def sync
  if self.class.sync && !self.class.sync_to.nil?
    user = self.dup
    last_update = user.attributes.delete "updated_at"
    local_user = self.class.sync_to.find_or_initialize_by_username user.username, user.attributes
    
    unless local_user.new_record?
      local_user.update_attributes user.attributes            
    else
      self.sync_to.default_data.each do |key,value|
        local_user.send(key.to_s + '=', value)
      end          
      
      local_user.save
    end
  else
    false
  end
end