Permalink
Browse files

Move zorro shit into app/services/zorro

  • Loading branch information...
NuckChorris committed Aug 29, 2017
1 parent 733329a commit 1bc6f47a09388f4fa2d9c0a428d96d259020b9bc
Showing with 26 additions and 17 deletions.
  1. +11 −0 {lib → app/services}/zorro.rb
  2. +15 −17 {lib → app/services}/zorro/user_matcher.rb
@@ -10,5 +10,16 @@ module DB
TimelinePost = Client['TimelinePost']
Thread = Client['Thread']
AnimeProgress = Client['AnimeProgress']
def self.assoc(assoc)
case assoc
when String
collection, id = assoc.split('$')
Zorro::Client[collection].find(_id: id).limit(1).first
when Hash
collection, id = assoc.values_at('className', 'objectId')
Zorro::Client[collection].find(_id: id).limit(1).first
end
end
end
end
@@ -1,22 +1,28 @@
module Zorro
class UserMatcher
attr_reader :user
def initialize(user)
@user = user
@user = UserWrapper.new(user)
end
def apply!
target_user.save!
end
def target_user
case conflict_resolution
when :merge then email_user
when :rename, nil then ::User.new(name: target_username)
when :rename, nil
User.new.tap do |user|
@user.new.merge_onto(user)
user.name = target_username
end
end
end
def target_username
if conflict_resolution == :rename
"aozora_#{@user['aozoraUsername']}"
else
@user['aozoraUsername']
end
conflict_resolution == :rename ? "aozora_#{@user.name}" : @user.name
end
def conflict
@@ -32,27 +38,19 @@ def conflict_resolution
private
def email_user
@email_user ||= ::User.by_email(email).first
@email_user ||= User.by_email(@user.email).first
end
def email_conflict?
email_user.present?
end
def name_user
@name_user ||= ::User.by_name(username).first
@name_user ||= User.by_name(@user.name).first
end
def name_conflict?
name_user.present?
end
def username
@user['aozoraUsername']
end
def email
@user['email']
end
end
end

0 comments on commit 1bc6f47

Please sign in to comment.