Created
March 13, 2013 22:34
-
-
Save danjesus/5157042 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
# ... | |
def self.sync_users | |
users_to_sync = where synced: false | |
SyncUsers.new(users_to_sync).tap &:sync | |
end | |
# ... | |
end | |
class UsersSyncer | |
attr_reader :users_to_sync | |
def initialize(users_to_sync) | |
@users_to_sync = users_to_sync | |
end | |
def sync | |
users_to_sync.each(&:sync!) | |
@has_synced_users = true | |
end | |
def synced_users | |
has_synced_users? ? users_to_sync : [] | |
end | |
def has_synced_users? | |
!!@has_synced_users | |
end | |
end | |
sync_users = User.sync_users | |
synced_users = sync_users.synced_users |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment