From 706e534455e2137c324c0ebb30435e7630ab7c1f Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 27 Nov 2017 22:47:06 +0100 Subject: Add UI for setting up account migration (#5832) --- app/models/form/migration.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 app/models/form/migration.rb (limited to 'app/models/form/migration.rb') diff --git a/app/models/form/migration.rb b/app/models/form/migration.rb new file mode 100644 index 000000000..53cee7ee1 --- /dev/null +++ b/app/models/form/migration.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class Form::Migration + include ActiveModel::Validations + + attr_accessor :acct, :account + + validates :acct, presence: true + + def initialize(attrs = {}) + @account = attrs[:account] + @acct = attrs[:account].acct unless @account.nil? + @acct = attrs[:acct].gsub(/\A@/, '').strip unless attrs[:acct].nil? + end + + def valid? + return false unless super + set_account + errors.empty? + end + + private + + def set_account + self.account = ResolveRemoteAccountService.new.call(acct) if account.nil? && acct.present? + end +end -- cgit