about summary refs log tree commit diff
path: root/app/models/form/migration.rb
blob: c2a8655e13211d8c41bd7d39fbb93e6cd4a34cfd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# frozen_string_literal: true

class Form::Migration
  include ActiveModel::Validations

  attr_accessor :acct, :account

  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 = (ResolveAccountService.new.call(acct) if account.nil? && acct.present?)
  end
end