about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorDavid Yip <yipdw@member.fsf.org>2017-11-27 22:33:26 -0600
committerDavid Yip <yipdw@member.fsf.org>2017-11-27 22:33:26 -0600
commit7463d80ff442833a4ad299460f37c27be9b8cda1 (patch)
treeeb84f712515a4b5c59a36cbc0340781c6765a545 /app/models
parent8bad6bdd00254484e04570b7a631403c24e73939 (diff)
parent706e534455e2137c324c0ebb30435e7630ab7c1f (diff)
Merge remote-tracking branch 'tootsuite/master'
Diffstat (limited to 'app/models')
-rw-r--r--app/models/form/migration.rb27
1 files changed, 27 insertions, 0 deletions
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