Class: InvestorProfileForm

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, Validator
Defined in:
app/form_models/investor_profile_form.rb

Defined Under Namespace

Modules: Validator

Constant Summary collapse

AggregateRoot =
Member

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Validator

#age_must_be_above_18, #id_document_blank?, #is_passport_blank_and_not_local_region?, #name_and_account_holder_must_be_the_same

Instance Attribute Details

#bank_accountObject

Returns the value of attribute bank_account.



5
6
7
# File 'app/form_models/investor_profile_form.rb', line 5

def 
  
end

#investor_accountObject

Returns the value of attribute investor_account.



5
6
7
# File 'app/form_models/investor_profile_form.rb', line 5

def 
  
end

#memberObject

Returns the value of attribute member.



5
6
7
# File 'app/form_models/investor_profile_form.rb', line 5

def member
  @member
end

Class Method Details

.find(id) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'app/form_models/investor_profile_form.rb', line 35

def find(id)
  member = AggregateRoot.find id
   = member.
   = .bank_accounts.first
  attrs = member.attributes.merge(.attributes).merge(.attributes)
  form = self.new attrs
  form.set_model id
  return form
end

.sanitized_params(params) ⇒ Object



55
56
57
58
# File 'app/form_models/investor_profile_form.rb', line 55

def sanitized_params(params)
  params[:date_of_birth] = Date.parse("#{params['date_of_birth(3i)']}-#{params['date_of_birth(2i)']}-#{params['date_of_birth(1i)']}")
  return params
end

.update(params) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'app/form_models/investor_profile_form.rb', line 45

def update(params)
  if params[:model_id].blank?
    raise 'Model ID not found'
  end
  form = self.new sanitized_params(params)
  form.set_model params[:model_id]
  form.persist(params)
  return form
end

Instance Method Details

#persist(params) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/form_models/investor_profile_form.rb', line 68

def persist(params)
  params.each do |k,v|
    setter_method = "#{k}="
    if @member.respond_to? setter_method
      @member.send setter_method, v
    end
    if .respond_to? setter_method
      .send setter_method, v
    end
    if .respond_to? setter_method
      .send setter_method, v
    end
  end
  @member.save!
  .save!
  .save!
end

#set_model(member_id) ⇒ Object



61
62
63
64
65
66
# File 'app/form_models/investor_profile_form.rb', line 61

def set_model(member_id)
  @model_id = (member_id.respond_to? :id)? member_id.id : member_id
  @member = AggregateRoot.find member_id
   = @member.
   = .bank_accounts.first
end