feidee_utils 0.0.4.1 → 0.0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/feidee_utils/account.rb +7 -2
- data/lib/feidee_utils/mixins/parent_and_path.rb +3 -1
- data/lib/feidee_utils/record/accessors.rb +18 -0
- data/lib/feidee_utils/record/persistent.rb +3 -1
- data/lib/feidee_utils/transaction.rb +14 -2
- data/lib/feidee_utils/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f30f41d070995fbe8c9f6b7de1b2d777f3a6e674
|
4
|
+
data.tar.gz: 82c6dbf50bf2922e6852304e0ecd699139413a64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 374fe584c1e52e9f0afde15512f1c1b476a8c37a3b5fbeed640e1f3058216709e5a228417196a137d32e364f1da23b789b30b3503a7dcc690d3611461109635b
|
7
|
+
data.tar.gz: bacc8d82f893a130eef2a84d2ce5e4ffd07b606881a90c270343812b587d0a6be6d32ec7a124380101be599b1bbf7f491291e149ce66bf6d894202a9e7db75ef
|
data/lib/feidee_utils/account.rb
CHANGED
@@ -5,7 +5,7 @@ require 'bigdecimal'
|
|
5
5
|
module FeideeUtils
|
6
6
|
class Account < Record
|
7
7
|
def validate_integrity
|
8
|
-
raise "Account type should always be 0, but it's #{field["type"]}.\n" + inspect unless field["type"] == 0
|
8
|
+
raise "Account type should always be 0, but it's #{field["type"]}.\n" + inspect unless not field["type"] or field["type"] == 0
|
9
9
|
raise "Account usedCount should always be 0, but it's #{field["usedCount"]}.\n" + inspect unless field["usedCount"] == 0
|
10
10
|
raise "Account uuid should always be empty, but it's #{field["uuid"]}.\n" + inspect unless field["uuid"].to_s.empty?
|
11
11
|
raise "Account hierachy contains more than 2 levels.\n" + inspect unless flat_parent_hierachy?
|
@@ -19,6 +19,8 @@ module FeideeUtils
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
NullPOID = 0
|
23
|
+
|
22
24
|
FieldMappings = {
|
23
25
|
name: "name",
|
24
26
|
raw_balance: "balance",
|
@@ -35,9 +37,12 @@ module FeideeUtils
|
|
35
37
|
|
36
38
|
IgnoredFields = [
|
37
39
|
"tradingEntityPOID",
|
40
|
+
# TODO: Field type is removed from database_version 73. Not sure about
|
41
|
+
# earlier versions.
|
38
42
|
"type", # Always 0
|
39
43
|
"usedCount", # Always 0
|
40
44
|
"uuid", # Always empty.
|
45
|
+
# TODO: code is also removed.
|
41
46
|
"code", # WTF
|
42
47
|
"clientID", # WTF
|
43
48
|
].freeze
|
@@ -75,7 +80,7 @@ module FeideeUtils
|
|
75
80
|
end
|
76
81
|
|
77
82
|
def has_parent?
|
78
|
-
parent_poid !=
|
83
|
+
parent_poid != NullPOID && !flagged_as_parent?
|
79
84
|
end
|
80
85
|
|
81
86
|
def flagged_as_parent?
|
@@ -4,6 +4,8 @@ module FeideeUtils
|
|
4
4
|
# instance methods: poid, parent_poid, raw_path
|
5
5
|
# class methods: find_by_id
|
6
6
|
module ParentAndPath
|
7
|
+
NullPOID = 0
|
8
|
+
|
7
9
|
class InconsistentDepthException < Exception
|
8
10
|
end
|
9
11
|
|
@@ -62,7 +64,7 @@ module FeideeUtils
|
|
62
64
|
end
|
63
65
|
|
64
66
|
def has_parent?
|
65
|
-
parent_poid !=
|
67
|
+
parent_poid != NullPOID
|
66
68
|
end
|
67
69
|
end
|
68
70
|
end
|
@@ -16,6 +16,24 @@ module FeideeUtils
|
|
16
16
|
define_method name do field[key] end
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
def define_entity_accessor poid_callback_name, target_class_name = nil
|
21
|
+
accessor_name = poid_callback_name.to_s.chomp!("_poid")
|
22
|
+
if accessor_name == nil
|
23
|
+
raise "No trailing 'poid' in callback name #{poid_callback_name}."
|
24
|
+
end
|
25
|
+
|
26
|
+
if not target_class_name
|
27
|
+
target_class_name = accessor_name
|
28
|
+
end
|
29
|
+
target_class_name = target_class_name.to_s.clone
|
30
|
+
target_class_name.gsub!(/(^|_)(.)/) { $2.upcase }
|
31
|
+
|
32
|
+
define_method accessor_name do
|
33
|
+
poid = method(poid_callback_name).call
|
34
|
+
self.class.environment.const_get(target_class_name).find(poid)
|
35
|
+
end
|
36
|
+
end
|
19
37
|
end
|
20
38
|
end
|
21
39
|
end
|
@@ -14,7 +14,9 @@ module FeideeUtils
|
|
14
14
|
end
|
15
15
|
|
16
16
|
id_field_name = entity_name.sub(/^[A-Z]/) { $&.downcase } + "POID"
|
17
|
-
|
17
|
+
entity_name_underscore =
|
18
|
+
entity_name.gsub(/([a-z\d])([A-Z\d])/, '\1_\2').downcase
|
19
|
+
table_name = "t_" + entity_name_underscore
|
18
20
|
subclass.class_exec do
|
19
21
|
define_singleton_method :entity_name do entity_name end
|
20
22
|
define_singleton_method :id_field_name do id_field_name end
|
@@ -11,7 +11,7 @@ module FeideeUtils
|
|
11
11
|
class TransferWithCategoryException < Exception
|
12
12
|
end
|
13
13
|
|
14
|
-
class
|
14
|
+
class InconsistentBuyerAndSellerException < Exception
|
15
15
|
end
|
16
16
|
|
17
17
|
class InconsistentCategoryException < Exception
|
@@ -36,7 +36,7 @@ module FeideeUtils
|
|
36
36
|
end
|
37
37
|
else
|
38
38
|
unless (buyer_account_poid == 0) ^ (seller_account_poid == 0)
|
39
|
-
raise
|
39
|
+
raise InconsistentBuyerAndSellerException,
|
40
40
|
"Exactly one of buyer and seller should be set in a non-transfer transaction. " +
|
41
41
|
"Buyer account POID: #{buyer_account_poid}. Seller account POID: #{seller_account_poid}.\n" +
|
42
42
|
inspect
|
@@ -98,6 +98,8 @@ module FeideeUtils
|
|
98
98
|
raw_seller_addition: "sellerMoney",
|
99
99
|
uuid: "relation",
|
100
100
|
}.freeze
|
101
|
+
define_entity_accessor :buyer_account_poid, :account
|
102
|
+
define_entity_accessor :seller_account_poid, :account
|
101
103
|
|
102
104
|
IgnoredFields = [
|
103
105
|
"creatorTradingEntityPOID",
|
@@ -141,6 +143,7 @@ module FeideeUtils
|
|
141
143
|
# At least one of those two must be 0.
|
142
144
|
buyer_category_poid + seller_category_poid
|
143
145
|
end
|
146
|
+
define_entity_accessor :category_poid
|
144
147
|
|
145
148
|
# Amount accessors
|
146
149
|
|
@@ -174,6 +177,7 @@ module FeideeUtils
|
|
174
177
|
buyer_account_poid + seller_account_poid
|
175
178
|
end
|
176
179
|
end
|
180
|
+
define_entity_accessor :revised_account_poid, :account
|
177
181
|
|
178
182
|
def revised_amount
|
179
183
|
account_poid = revised_account_poid
|
@@ -202,6 +206,14 @@ module FeideeUtils
|
|
202
206
|
|
203
207
|
private
|
204
208
|
def sign_by_type num
|
209
|
+
# This is awkward. For transactions of type positive_initial_balance, the
|
210
|
+
# buyer is always 0, but the seller have to **add** the amount shown as
|
211
|
+
# sellerMoney, which is consistent with other type of transactions.
|
212
|
+
#
|
213
|
+
# Whereas for transactions of type negative_initial_balance (9), the
|
214
|
+
# buyer is always 0, and the seller will have to **deduct** the amount
|
215
|
+
# shown as sellerMoney from balance. Here the sign of
|
216
|
+
# negative_initial_balance is reversed to reflect this awkwardness.
|
205
217
|
raw_type == 9 ? -num : num
|
206
218
|
end
|
207
219
|
|
data/lib/feidee_utils/version.rb
CHANGED