nexus_core 0.5.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d397d4a83206b0252f4a7a4f3091e3917a9ec952
4
- data.tar.gz: 281c0120b3d8960ac303185b6788533cce3038b3
3
+ metadata.gz: 4539337c664651ef414aebdb3f59affdb3d6ab7d
4
+ data.tar.gz: e9c50c15bfbfa5656c58960786abb70dd12781f9
5
5
  SHA512:
6
- metadata.gz: afbdaebfcb5a24c6cc732982065fa9eb818f92ffbff8999c9dc4dc143e069b1603dcd7f3b3cf48bf4c48edf2074265adbbb5be40a7774838c951737b5539f142
7
- data.tar.gz: b853e48b49862d9ea047f0ff691f425059052e8602402ac3e34f49726fefd6abb6c9c5879f69e288668c9f2c13f82c3c1c89d738559e8cc790fdd9b483293f03
6
+ metadata.gz: 820bff9ba3cdda432f2e3d0704954552bed71ac2b80fb620ed719b40aaa49a74e558810d62fe5845b7a65d66255bda0a2e9707b48b5522d15d29b1a539663082
7
+ data.tar.gz: 4bfc0a707e01ac3229b8297e263b5a3216357e8b6d43a644d4dd49cb0d8b5d0978c9f3ce7a6ecc3c78b2ecc68bd88f58419dd78f205a4d89585039d0706e60b7
@@ -0,0 +1,8 @@
1
+ module BankAccountAccessor
2
+ def self.included(base)
3
+ base.class_eval do
4
+ belongs_to :investor_account
5
+ has_many :wallets, dependent: :destroy
6
+ end
7
+ end
8
+ end
@@ -2,8 +2,9 @@ module InvestorAccountAccessor
2
2
  def self.included(base)
3
3
  base.class_eval do
4
4
  belongs_to :member
5
+ has_many :wallets # will be destroyed by bank account cascade destroy
5
6
  has_many :bank_accounts, dependent: :destroy
6
- has_many :wallets, dependent: :destroy
7
+ has_many :investor_state_transitions, dependent: :destroy, class_name: InvestorAccount.investor_state_transition_klass.to_s
7
8
  end
8
9
  end
9
10
 
@@ -19,12 +20,4 @@ module InvestorAccountAccessor
19
20
  def long_account_id
20
21
  'U' + id.to_s.rjust(6, '0')
21
22
  end
22
-
23
- def approved?
24
- approval_status == STATUS_APPROVED
25
- end
26
-
27
- def pending?
28
- approval_status == STATUS_PENDING_VERIFICATION
29
- end
30
23
  end
@@ -3,6 +3,7 @@ module MemberAccessor
3
3
  base.class_eval do
4
4
  has_many :identities, dependent: :destroy, primary_key: :email, foreign_key: :email
5
5
  has_one :member_profile, dependent: :destroy
6
+ alias_method :profile, :member_profile
6
7
  has_one :investor_account, dependent: :destroy
7
8
  alias_method :investor, :investor_account
8
9
  has_one :preference, dependent: :destroy
@@ -0,0 +1,8 @@
1
+ module MemberProfileDelegation
2
+ module Instance
3
+ def method_missing(method_sym, *args)
4
+ return member.send(method_sym, *args) if member.respond_to?(method_sym)
5
+ super
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,126 @@
1
+ class InvestorProfileForm
2
+ include ActiveModel::Model
3
+ include Virtus.model
4
+
5
+ attr_accessor :member, :investor_account, :bank_account
6
+ attribute :model_id, Integer
7
+
8
+ AggregateRoot = Member
9
+
10
+ # Member fields
11
+ attribute :name, String
12
+ attribute :nationality, String
13
+ attribute :id_number, String
14
+ attribute :date_of_birth, Date
15
+ attribute :phone_number, String
16
+ attribute :address1, String
17
+ attribute :address2, String
18
+ attribute :city, String
19
+ attribute :postal_code, String
20
+ attribute :country_of_residence, String
21
+ attribute :id_document, String
22
+ attribute :id_document_additional, String
23
+ attribute :proof_of_residence, String
24
+
25
+ # Bank account fields
26
+ attribute :account_holder, String
27
+ attribute :account_number, String
28
+ attribute :account_type, String
29
+ attribute :bank_name, String
30
+ attribute :bank_address, String
31
+ attribute :bank_country, String
32
+ attribute :swift_code, String
33
+
34
+ class << self
35
+ def find(id)
36
+ member = AggregateRoot.find id
37
+ investor_account = member.investor_account
38
+ bank_account = investor_account.bank_accounts.first
39
+ attrs = member.attributes.merge(investor_account.attributes).merge(bank_account.attributes)
40
+ form = self.new attrs
41
+ form.set_model id
42
+ return form
43
+ end
44
+
45
+ def update(params)
46
+ if params[:model_id].blank?
47
+ raise 'Model ID not found'
48
+ end
49
+ form = self.new sanitized_params(params)
50
+ form.set_model params[:model_id]
51
+ form.persist(params)
52
+ return form
53
+ end
54
+
55
+ def sanitized_params(params)
56
+ params[:date_of_birth] = Date.parse("#{params['date_of_birth(3i)']}-#{params['date_of_birth(2i)']}-#{params['date_of_birth(1i)']}")
57
+ return params
58
+ end
59
+ end
60
+
61
+ def set_model(member_id)
62
+ @model_id = (member_id.respond_to? :id)? member_id.id : member_id
63
+ @member = AggregateRoot.find member_id
64
+ @investor_account = @member.investor_account
65
+ @bank_account = @investor_account.bank_accounts.first
66
+ end
67
+
68
+ def persist(params)
69
+ params.each do |k,v|
70
+ setter_method = "#{k}="
71
+ if @member.respond_to? setter_method
72
+ @member.send setter_method, v
73
+ end
74
+ if @investor_account.respond_to? setter_method
75
+ @investor_account.send setter_method, v
76
+ end
77
+ if @bank_account.respond_to? setter_method
78
+ @bank_account.send setter_method, v
79
+ end
80
+ end
81
+ @member.save!
82
+ @investor_account.save!
83
+ @bank_account.save!
84
+ end
85
+
86
+ module Validator
87
+ extend ActiveSupport::Concern
88
+
89
+ included do
90
+ validates_presence_of :name,
91
+ :id_number, :date_of_birth, :phone_number,
92
+ :address1, :city, :postal_code,
93
+ :country_of_residence, :nationality,
94
+ :account_holder, :account_number, :account_type,
95
+ :bank_country, :bank_name
96
+
97
+ validates_presence_of :id_document, if: :id_document_blank?
98
+ validates_presence_of :id_document_additional, if: :is_passport_blank_and_not_local_region?
99
+ validate :age_must_be_above_18
100
+ validate :name_and_account_holder_must_be_the_same
101
+ end
102
+
103
+ def age_must_be_above_18
104
+ too_young = date_of_birth.present? && TimeDifference.between(date_of_birth, Date.today).in_years.to_i < 18
105
+ errors.add(:date_of_birth, I18n.t('investor_form.must_be_older_than_18')) if too_young
106
+ end
107
+
108
+ def name_and_account_holder_must_be_the_same
109
+ if name.to_s != account_holder.to_s
110
+ msg = I18n.t('investor_form.name_and_account_holder_must_be_the_same')
111
+ errors.add(:name, msg)
112
+ errors.add(:account_holder, msg)
113
+ end
114
+ end
115
+
116
+ def id_document_blank?
117
+ @member.id_document.blank?
118
+ end
119
+
120
+ def is_passport_blank_and_not_local_region?
121
+ is_local_region = %w(Singapore Indonesia).include? nationality
122
+ !is_local_region && @member.id_document_additional.blank?
123
+ end
124
+ end
125
+ include Validator
126
+ end
@@ -0,0 +1,60 @@
1
+ class InvestorTierForm
2
+ include ActiveModel::Model
3
+ include Virtus.model
4
+
5
+ attr_accessor :member, :investor_account
6
+ attribute :model_id, Integer
7
+
8
+
9
+ class << self
10
+ def find(id)
11
+ member = Member.find id
12
+ form = self.new member.attributes.merge(member.investor_account && member.investor_account.attributes || {})
13
+ form.set_model id
14
+ return form
15
+ end
16
+
17
+ def update(params)
18
+ if params[:model_id].blank?
19
+ raise 'Model ID not found'
20
+ end
21
+ form = self.new sanitized_params(params)
22
+ form.set_model params[:model_id]
23
+ form.persist(params)
24
+ return form
25
+ end
26
+
27
+ def sanitized_params(params)
28
+ return params
29
+ end
30
+ end
31
+
32
+ def set_model(member_id)
33
+ @model_id = (member_id.respond_to? :id)? member_id.id : member_id
34
+ @member = Member.find member_id
35
+ @investor_account = @member.investor.blank?? InvestorAccount.create!(member: @member) : @member.investor
36
+ end
37
+
38
+ def persist(params)
39
+ params.each do |k,v|
40
+ setter_method = "#{k}="
41
+ if @member.respond_to? setter_method
42
+ @member.send setter_method, v
43
+ end
44
+ if @investor_account.respond_to? setter_method
45
+ @investor_account.send setter_method, v
46
+ end
47
+ end
48
+ @member.save!
49
+ @investor_account.save!
50
+ end
51
+
52
+ module Validator
53
+ extend ActiveSupport::Concern
54
+
55
+ included do
56
+ end
57
+
58
+ end
59
+ include Validator
60
+ end
data/lib/nexus_core.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'nexus_core/engine'
2
+ require 'nexus_core/geoip_dat_location'
2
3
  require 'nexus_core/report_utils'
3
4
 
4
5
  module NexusCore
@@ -0,0 +1,3 @@
1
+ module NexusCore
2
+ GEOIP_DAT_LOCATION = File.join(File.expand_path('../../../data', __FILE__), 'GeoIP.dat')
3
+ end
@@ -54,7 +54,7 @@ module NexusCore
54
54
  extend PercentageHelper
55
55
 
56
56
  def self.decode_ip(ip_addr)
57
- g = GeoIP.new(File.join(Gem.datadir('nexus_core'), 'GeoIP.dat'))
57
+ g = GeoIP.new(NexusCore::GEOIP_DAT_LOCATION)
58
58
  begin
59
59
  country = g.country(ip_addr).country_name
60
60
  rescue
@@ -1,3 +1,3 @@
1
1
  module NexusCore
2
- VERSION = '0.5.0'
3
- end
2
+ VERSION = '0.6.1'
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexus_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Tioh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-11 00:00:00.000000000 Z
11
+ date: 2016-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -78,6 +78,20 @@ dependencies:
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
80
  version: 1.6.2
81
+ - !ruby/object:Gem::Dependency
82
+ name: virtus
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
81
95
  description: ''
82
96
  email:
83
97
  - felixsagitta@gmail.com
@@ -88,6 +102,7 @@ files:
88
102
  - MIT-LICENSE
89
103
  - README.md
90
104
  - Rakefile
105
+ - app/accessors/bank_account_accessor.rb
91
106
  - app/accessors/investor_account_accessor.rb
92
107
  - app/accessors/journal_entry_accessor.rb
93
108
  - app/accessors/member_accessor.rb
@@ -101,8 +116,11 @@ files:
101
116
  - app/constants/withdrawal_constants.rb
102
117
  - app/delegations/investor_account_delegation.rb
103
118
  - app/delegations/member_delegation.rb
119
+ - app/delegations/member_profile_delegation.rb
104
120
  - app/delegations/top_up_delegation.rb
105
121
  - app/delegations/withdrawal_delegation.rb
122
+ - app/form_models/investor_profile_form.rb
123
+ - app/form_models/investor_tier_form.rb
106
124
  - app/lifecycle/investor_account_lifecycle.rb
107
125
  - app/lifecycle/member_lifecycle.rb
108
126
  - app/lifecycle/top_up_lifecycle.rb
@@ -112,6 +130,7 @@ files:
112
130
  - app/state_machines/withdrawal_state_machine.rb
113
131
  - lib/nexus_core.rb
114
132
  - lib/nexus_core/engine.rb
133
+ - lib/nexus_core/geoip_dat_location.rb
115
134
  - lib/nexus_core/report_utils.rb
116
135
  - lib/nexus_core/version.rb
117
136
  - lib/tasks/nexus_core_tasks.rake