feidee_utils 0.0.4.6 → 0.0.4.7

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: cdc81f2ed8b63e0e750f6b53dac1bc925eb3b509
4
- data.tar.gz: 25397ff7b32f52165c711ba6789d7393889257af
3
+ metadata.gz: 26b9e39c2cd9ea69a6183b406b9baae7877afe5e
4
+ data.tar.gz: 44ad306d6594bd09d1c6442bcfdc11331ee67509
5
5
  SHA512:
6
- metadata.gz: 995ecd1e223cf972c5a6724ebb5117dc5a9e1c621f5902a628b3a592f62d925acfdf9b9881235d47741d46c3bff28dd2416b319c2208016624759ed33b4bf746
7
- data.tar.gz: ce41000745f1d36772dd4bfaf2d7a2f2ac881b8adc09338f3023e6ba93a8e95464b6f8b7c55bc4e600a71fb95ed57891568c4939a2560b63002c5e8cda37ffbb
6
+ metadata.gz: 854d3923620bf6518e22de9acf89db1de67a9a664d4d81189471dd6bb57a143f7eb9c39c869396a50f3d7cde18c9d737f70954d74c49a5b082a5a837e93e2c54
7
+ data.tar.gz: 33d9fe851f98087c7a675904d8d2b21d801beac6764bcacf8c719c6c4f238b43149024ee71593b17989e946197cf717701fe4946ae1844a4c9ac9f5295514bea
@@ -51,6 +51,7 @@ module FeideeUtils
51
51
  account_group_poid: "accountGroupPOID",
52
52
  raw_hidden: "hidden",
53
53
  }.freeze
54
+ define_entity_accessor :account_group_poid, :account_group
54
55
 
55
56
  IgnoredFields = [
56
57
  "tradingEntityPOID", # Foreign key to t_user or maybe t_tradingEntity.
@@ -84,10 +85,6 @@ module FeideeUtils
84
85
  raw_hidden == 1
85
86
  end
86
87
 
87
- def account_group
88
- self.class.environment::AccountGroup.find_by_id(account_group_poid)
89
- end
90
-
91
88
  # Parent related.
92
89
  def parent
93
90
  self.class.find_by_id(parent_poid)
@@ -17,16 +17,17 @@ module FeideeUtils
17
17
  end
18
18
  end
19
19
 
20
+ ProjectRootTypeCode = 2
21
+
20
22
  def self.validate_global_integrity
21
- project_root_code = 2
22
- if TypeEnum[project_root_code] != :project_root
23
+ if TypeEnum[ProjectRootTypeCode] != :project_root
23
24
  raise "The type code of project root has been changed," +
24
25
  " please update the code."
25
26
  end
26
27
 
27
28
  rows = self.database.execute <<-SQL
28
29
  SELECT #{id_field_name}, #{FieldMappings[:name]} FROM #{table_name}
29
- WHERE #{FieldMappings[:raw_type]}=#{project_root_code};
30
+ WHERE #{FieldMappings[:raw_type]}=#{ProjectRootTypeCode};
30
31
  SQL
31
32
 
32
33
  if rows.length > 1
@@ -0,0 +1,19 @@
1
+ module FeideeUtils
2
+ class Record
3
+ module Computed
4
+ module ClassMethods
5
+ def computed field_name, &block
6
+ var_name = ("@" + field_name.to_s).to_sym
7
+ define_method field_name do
8
+ if instance_variable_defined? var_name
9
+ instance_variable_get var_name
10
+ else
11
+ val = instance_exec &block
12
+ instance_variable_set var_name, val
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,4 +1,5 @@
1
1
  require 'feidee_utils/record/accessors'
2
+ require 'feidee_utils/record/computed'
2
3
  require 'feidee_utils/record/namespaced'
3
4
  require 'feidee_utils/record/persistent'
4
5
  require 'feidee_utils/record/utils'
@@ -59,6 +60,8 @@ module FeideeUtils
59
60
  include Accessors
60
61
  # Helper methods to define accessors
61
62
  extend Accessors::ClassMethods
63
+ # Helper methods to define computed fields.
64
+ extend Computed::ClassMethods
62
65
  # Helper methods to define new classes in a given namespace.
63
66
  extend Namespaced::ClassMethods
64
67
  # Helper methods to look up records.
@@ -133,15 +133,15 @@ module FeideeUtils
133
133
  9 => :negative_initial_balance,
134
134
  })
135
135
 
136
- def created_at
136
+ computed :created_at do
137
137
  timestamp_to_time(raw_created_at)
138
138
  end
139
139
 
140
- def modified_at
140
+ computed :modified_at do
141
141
  timestamp_to_time(raw_modified_at)
142
142
  end
143
143
 
144
- def trade_at
144
+ computed :trade_at do
145
145
  timestamp_to_time(raw_trade_at)
146
146
  end
147
147
 
@@ -1,3 +1,3 @@
1
1
  module FeideeUtils
2
- VERSION = '0.0.4.6'
2
+ VERSION = '0.0.4.7'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feidee_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.6
4
+ version: 0.0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liqing Muyi
@@ -132,6 +132,7 @@ files:
132
132
  - lib/feidee_utils/mixins/type.rb
133
133
  - lib/feidee_utils/record.rb
134
134
  - lib/feidee_utils/record/accessors.rb
135
+ - lib/feidee_utils/record/computed.rb
135
136
  - lib/feidee_utils/record/modified_record.rb
136
137
  - lib/feidee_utils/record/namespaced.rb
137
138
  - lib/feidee_utils/record/persistent.rb
@@ -158,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
159
  version: '0'
159
160
  requirements: []
160
161
  rubyforge_project:
161
- rubygems_version: 2.4.6
162
+ rubygems_version: 2.5.2
162
163
  signing_key:
163
164
  specification_version: 4
164
165
  summary: Utils to extract useful information from Feidee Mymoney backup.