unidom-common 2.1.1 → 3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -265
- data/app/models/unidom/common/concerns/aes256_cryptor.rb +8 -3
- data/app/models/unidom/common/concerns/model_extension.rb +13 -0
- data/lib/unidom/common/engine_extension.rb +34 -28
- data/lib/unidom/common/neglection.rb +21 -16
- data/lib/unidom/common/numeration.rb +20 -15
- data/lib/unidom/common/version.rb +1 -1
- data/lib/unidom/common/yaml_helper.rb +21 -16
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c71146870a9030fc64208ac28ed4bc6f7a92530432a95ffcbb5166d13ad7527
|
4
|
+
data.tar.gz: b045e9c5680d646c078d9b6b16e1ecac57f6b4b5db15c48b37e0158919ef5141
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5dd9f8e8d2a8f5f0daf8185c3f3162a1ad6b0290c2433914a34f4198e02f7b7a522a47cb857bc9c34c3c06c5c4899bea85120fb6ca2d190bb2425d2e00f4945c
|
7
|
+
data.tar.gz: 7f4259427bbb8377258e12c630b19eec5aff6310df53201d2d56ae6b927759c200d3082b771fa1161b1b8aa684fb482b95de92c7366c45406e102780062844f6
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
[![Dependency Status](https://gemnasium.com/badges/github.com/topbitdu/unidom-common.svg)](https://gemnasium.com/github.com/topbitdu/unidom-common)
|
8
8
|
|
9
9
|
Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Common domain model engine includes the common models.
|
10
|
-
Unidom
|
10
|
+
Unidom (统一领域对象模型)是一系列的领域模型引擎。常用领域模型引擎包括一些常用的模型。
|
11
11
|
|
12
12
|
|
13
13
|
|
@@ -134,7 +134,7 @@ Project.notation_boolean_column_where(:enabled, true) # All enabled projects
|
|
134
134
|
|
135
135
|
```ruby
|
136
136
|
# db/migrate/YYYYMMDDHHMMSS_create_people.rb
|
137
|
-
class CreatePeople < ActiveRecord::Migration[
|
137
|
+
class CreatePeople < ActiveRecord::Migration[6.0]
|
138
138
|
|
139
139
|
def change
|
140
140
|
|
@@ -189,7 +189,7 @@ Person.passport_number_is('E00000000').first==person # true
|
|
189
189
|
|
190
190
|
```ruby
|
191
191
|
# db/migrate/YYYYMMDDHHMMSS_create_orderings.rb
|
192
|
-
class CreateOrderings < ActiveRecord::Migration[
|
192
|
+
class CreateOrderings < ActiveRecord::Migration[6.0]
|
193
193
|
|
194
194
|
def change
|
195
195
|
|
@@ -553,268 +553,31 @@ end
|
|
553
553
|
|
554
554
|
### Domain Models (200YMMDDHHMMSS)
|
555
555
|
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
<ul>
|
582
|
-
<li>Identificating</li>
|
583
|
-
<li>Authenticating</li>
|
584
|
-
<li>Recognization</li>
|
585
|
-
<li>User</li>
|
586
|
-
<li>Guest</li>
|
587
|
-
<li>Password</li>
|
588
|
-
<ul>
|
589
|
-
</td>
|
590
|
-
<td>The Visitor domain model engine includes Identificating, Authenticating, Recognization, Visitor (User & Guest), and Password models. 访问者领域模型引擎包括身份标识、身份鉴别、身份识别、访问者(用户和游客)、密码的模型。</td>
|
591
|
-
</tr>
|
592
|
-
|
593
|
-
<tr>
|
594
|
-
<td><a href="https://github.com/topbitdu/unidom-category">unidom-category</a></td>
|
595
|
-
<td>200003DDHHMMSS</td>
|
596
|
-
<td>
|
597
|
-
<ul>
|
598
|
-
<li>Category</li>
|
599
|
-
<li>Categorizing</li>
|
600
|
-
<li>Category Rollup</li>
|
601
|
-
<li>Category Associating</li>
|
602
|
-
<ul>
|
603
|
-
</td>
|
604
|
-
<td>The Category domain model engine includes Category and its relative models. 类别领域模型引擎包括类别及其相关的模型。</td>
|
605
|
-
</tr>
|
606
|
-
|
607
|
-
<tr>
|
608
|
-
<td><a href="https://github.com/topbitdu/unidom-authorization">unidom-authorization</a></td>
|
609
|
-
<td>200004DDHHMMSS</td>
|
610
|
-
<td>
|
611
|
-
<ul>
|
612
|
-
<li>Permission</li>
|
613
|
-
<li>Authorizing</li>
|
614
|
-
<ul>
|
615
|
-
</td>
|
616
|
-
<td>The Authorization domain model engine includes the Permission and Authorizing models. 授权领域模型引擎包括权限、授权的模型。</td>
|
617
|
-
</tr>
|
618
|
-
|
619
|
-
<tr>
|
620
|
-
<td><a href="https://github.com/topbitdu/unidom-action">unidom-action</a></td>
|
621
|
-
<td>200005DDHHMMSS</td>
|
622
|
-
<td>
|
623
|
-
<ul>
|
624
|
-
<li>Reason</li>
|
625
|
-
<li>State Transition</li>
|
626
|
-
<li>Obsolescing</li>
|
627
|
-
<li>Acting</li>
|
628
|
-
</ul>
|
629
|
-
</td>
|
630
|
-
<td>The Action domain model engine includes the Reason, State Transition, Obsolescing, and the Acting models. 审计领域模型引擎包括原因、状态迁移、废弃和行为日志的模型。</td>
|
631
|
-
</tr>
|
632
|
-
|
633
|
-
<tr>
|
634
|
-
<td><a href="https://github.com/topbitdu/unidom-standard">unidom-standard</a></td>
|
635
|
-
<td>200006DDHHMMSS</td>
|
636
|
-
<td>
|
637
|
-
<ul>
|
638
|
-
<li>Standard</li>
|
639
|
-
<li>Standard Associating</li>
|
640
|
-
</ul>
|
641
|
-
</td>
|
642
|
-
<td>The Standard domain model engine includes the Standard model and the Standard Associating model. 标准领域模型引擎包括行为标准和标准关联的模型。</td>
|
643
|
-
</tr>
|
644
|
-
|
645
|
-
|
646
|
-
<tr>
|
647
|
-
<td><a href="https://github.com/topbitdu/unidom-party">unidom-party</a></td>
|
648
|
-
<td>200101DDHHMMSS</td>
|
649
|
-
<td>
|
650
|
-
<ul>
|
651
|
-
<li>Person</li>
|
652
|
-
<li>Shop</li>
|
653
|
-
<li>Company</li>
|
654
|
-
<li>Government Agency</li>
|
655
|
-
<li>Party Relation</li>
|
656
|
-
</ul>
|
657
|
-
</td>
|
658
|
-
<td>The Party domain model engine includes the Person, Shop, Company, Government Agency, and the Party Relation models. 参与者领域模型引擎包括个人、店铺、公司、政府机构、参与者关系的模型。</td>
|
659
|
-
</tr>
|
660
|
-
|
661
|
-
<tr>
|
662
|
-
<td><a href="https://github.com/topbitdu/unidom-certificate">unidom-certificate</a></td>
|
663
|
-
<td>200102DDHHMMSS</td>
|
664
|
-
<td>
|
665
|
-
<ul>
|
666
|
-
<li>Certificating</li>
|
667
|
-
</ul>
|
668
|
-
</td>
|
669
|
-
<td>The Certificate domain model engine includes the Certificating model.
|
670
|
-
证书领域模型引擎包括证书认证的模型。</td>
|
671
|
-
</tr>
|
672
|
-
|
673
|
-
<tr>
|
674
|
-
<td><a href="https://github.com/topbitdu/unidom-contact">unidom-contact</a></td>
|
675
|
-
<td>200103DDHHMMSS</td>
|
676
|
-
<td>
|
677
|
-
<ul>
|
678
|
-
<li>Contact Subscription</li>
|
679
|
-
<li>Email Address</li>
|
680
|
-
</ul>
|
681
|
-
</td>
|
682
|
-
<td>The Contact domain model engine includes the Contact Subscription and Email Address models. 联系方式领域模型引擎包括联系方式订阅和电子邮箱地址的模型。</td>
|
683
|
-
</tr>
|
684
|
-
|
685
|
-
<tr>
|
686
|
-
<td><a href="https://github.com/topbitdu/unidom-geo">unidom-geo</a></td>
|
687
|
-
<td>200104DDHHMMSS</td>
|
688
|
-
<td>
|
689
|
-
<ul>
|
690
|
-
<li>Location</li>
|
691
|
-
<li>Locating</li>
|
692
|
-
</ul>
|
693
|
-
</td>
|
694
|
-
<td>The Geo domain model engine includes the Location and Locating models. 地理领域模型引擎包括位置和定位的模型。</td>
|
695
|
-
</tr>
|
696
|
-
|
697
|
-
|
698
|
-
<tr>
|
699
|
-
<td><a href="https://github.com/topbitdu/unidom-article_number">unidom-article_number</a></td>
|
700
|
-
<td>200201DDHHMMSS</td>
|
701
|
-
<td>
|
702
|
-
<ul>
|
703
|
-
<li>Marking</li>
|
704
|
-
<li>EAN 13 Barcode</li>
|
705
|
-
<li>EAN 8 Barcode</li>
|
706
|
-
</ul>
|
707
|
-
</td>
|
708
|
-
<td>The Article Number domain model engine includes Marking, EAN-13, and EAN-8 models. 物品编码领域模型引擎包括打码、EAN-13和EAN-8的模型。</td>
|
709
|
-
</tr>
|
710
|
-
|
711
|
-
<tr>
|
712
|
-
<td><a href="https://github.com/topbitdu/unidom-product">unidom-product</a></td>
|
713
|
-
<td>200202DDHHMMSS</td>
|
714
|
-
<td>
|
715
|
-
<ul>
|
716
|
-
<li>Product</li>
|
717
|
-
<li>Product Associating</li>
|
718
|
-
</ul>
|
719
|
-
</td>
|
720
|
-
<td>The Product domain model engine includes Product and Produt Associating models. 产品领域模型引擎包括产品和产品关联的模型。</td>
|
721
|
-
</tr>
|
722
|
-
|
723
|
-
<tr>
|
724
|
-
<td><a href="https://github.com/topbitdu/unidom-price">unidom-price</a></td>
|
725
|
-
<td>200203DDHHMMSS</td>
|
726
|
-
<td>
|
727
|
-
<ul>
|
728
|
-
<li>Price</li>
|
729
|
-
</ul>
|
730
|
-
</td>
|
731
|
-
<td>The Price domain model engine includes Price and its relative models. 价格领域模型引擎包括定价及其相关的模型。</td>
|
732
|
-
</tr>
|
733
|
-
|
734
|
-
<tr>
|
735
|
-
<td><a href="https://github.com/topbitdu/unidom-shopping">unidom-shopping</a></td>
|
736
|
-
<td>200205DDHHMMSS</td>
|
737
|
-
<td>
|
738
|
-
<ul>
|
739
|
-
<li>Shopping Cart</li>
|
740
|
-
<li>Shopping Item</li>
|
741
|
-
</ul>
|
742
|
-
</td>
|
743
|
-
<td>The Shopping domain model engine includes Shopping Cart and Shopping Item models. 购物领域模型引擎包括购物车和购物项的模型。</td>
|
744
|
-
</tr>
|
745
|
-
|
746
|
-
<tr>
|
747
|
-
<td><a href="https://github.com/topbitdu/unidom-order">unidom-order</a></td>
|
748
|
-
<td>200206DDHHMMSS</td>
|
749
|
-
<td>
|
750
|
-
<ul>
|
751
|
-
<li>Order</li>
|
752
|
-
<li>Order Item</li>
|
753
|
-
<li>Order Adjustment</li>
|
754
|
-
</ul>
|
755
|
-
</td>
|
756
|
-
<td>The Order domain model engine includes Order, Order Item, and Order Adjustment models. 订单领域模型引擎包括订单、订单项和订单调整的模型。</td>
|
757
|
-
</tr>
|
758
|
-
|
759
|
-
<tr>
|
760
|
-
<td><a href="https://github.com/topbitdu/unidom-inventory">unidom-inventory</a></td>
|
761
|
-
<td>200209DDHHMMSS</td>
|
762
|
-
<td>
|
763
|
-
<ul>
|
764
|
-
<li>Serialized Inventory Item</li>
|
765
|
-
<li>Grouped Inventory Item</li>
|
766
|
-
<li>Lot</li>
|
767
|
-
<li>Inventory Item Variance</li>
|
768
|
-
</ul>
|
769
|
-
</td>
|
770
|
-
<td>The Inventory domain model engine includes the Serialized Inventory Item, the Grouped Inventory Item, the Lot, and the Inventory Item Variance models. 库存领域模型引擎包括序列化库存项、分组库存项、批量和库存项变化的模型。</td>
|
771
|
-
</tr>
|
772
|
-
|
773
|
-
<tr>
|
774
|
-
<td><a href="https://github.com/topbitdu/unidom-shipment">unidom-shipment</a></td>
|
775
|
-
<td>200210DDHHMMSS</td>
|
776
|
-
<td>
|
777
|
-
<ul>
|
778
|
-
<li>Shipment</li>
|
779
|
-
<li>Shipment Item</li>
|
780
|
-
<li>Shipment Package</li>
|
781
|
-
<li>Shipment Package Item</li>
|
782
|
-
<li>Shipment Receipt</li>
|
783
|
-
</ul>
|
784
|
-
</td>
|
785
|
-
<td>The Shipment domain model engine includes the Shipment, Shipment Item, Shipment Package, Shipment Package Item, and Shipment Receipt model. 装运领域模型引擎包括装运、装运项、装运包裹、装运包裹项、装运收据的模型。</td>
|
786
|
-
</tr>
|
787
|
-
|
788
|
-
|
789
|
-
<tr>
|
790
|
-
<td><a href="https://github.com/topbitdu/unidom-position">unidom-position</a></td>
|
791
|
-
<td>200402DDHHMMSS</td>
|
792
|
-
<td>
|
793
|
-
<ul>
|
794
|
-
<li>Occupation</li>
|
795
|
-
<li>Position</li>
|
796
|
-
<li>Post</li>
|
797
|
-
<li>Position Reporting Structure</li>
|
798
|
-
</ul>
|
799
|
-
</td>
|
800
|
-
<td>The Position domain model engine includes the Occupation, Position, Post, and Position Reporting Structure models.
|
801
|
-
职位领域模型引擎包括职业、职位、岗位及岗位报告关系模型。</td>
|
802
|
-
</tr>
|
803
|
-
|
804
|
-
<tr>
|
805
|
-
<td><a href="https://github.com/topbitdu/unidom-accession">unidom-accession</a></td>
|
806
|
-
<td>200405DDHHMMSS</td>
|
807
|
-
<td>
|
808
|
-
<ul>
|
809
|
-
<li>Post Fulfillment</li>
|
810
|
-
</ul>
|
811
|
-
</td>
|
812
|
-
<td>The Accession domain model engine includes the Post Fulfillment and its relative models. 就职领域模型引擎包括岗位履行及其相关的模型。</td>
|
813
|
-
</tr>
|
814
|
-
|
815
|
-
|
816
|
-
</tbody>
|
817
|
-
</table>
|
556
|
+
|Ruby Gem|Migration|Model|Description|
|
557
|
+
|--- |--- |--- |--- |
|
558
|
+
|unidom-common|200001DDHHMMSS|-|The Common domain model engine includes the common models. 常用领域模型引擎包括一些常用的模型。|
|
559
|
+
|unidom-visitor|200002DDHHMMSS|Identificating, Authenticating, Recognization, User, Guest, Password|The Visitor domain model engine includes Identificating, Authenticating, Recognization, Visitor (User & Guest), and Password models. 访问者领域模型引擎包括身份标识、身份鉴别、身份识别、访问者(用户和游客)、密码的模型。|
|
560
|
+
|unidom-category|200003DDHHMMSS|Category, Categorizing, Category Rollup, Category Associating|The Category domain model engine includes Category and its relative models. 类别领域模型引擎包括类别及其相关的模型。|
|
561
|
+
|unidom-authorization|200004DDHHMMSS|Permission, Authorizing|The Authorization domain model engine includes the Permission and Authorizing models. 授权领域模型引擎包括权限、授权的模型。|
|
562
|
+
|unidom-action|200005DDHHMMSS|Reason, State Transition, Obsolescing, Acting|The Action domain model engine includes the Reason, State Transition, Obsolescing, and the Acting models. 审计领域模型引擎包括原因、状态迁移、废弃和行为日志的模型。|
|
563
|
+
|unidom-standard|200006DDHHMMSS|Standard, Standard Associating|The Standard domain model engine includes the Standard model and the Standard Associating model. 标准领域模型引擎包括行为标准和标准关联的模型。|
|
564
|
+
|unidom-party|200101DDHHMMSS|Person, Shop, Company, Government Agency, Party Relation|The Party domain model engine includes the Person, Shop, Company, Government Agency, and the Party Relation models. 参与者领域模型引擎包括个人、店铺、公司、政府机构、参与者关系的模型。|
|
565
|
+
|unidom-certificate|200102DDHHMMSS|Certificating|The Certificate domain model engine includes the Certificating model.
|
566
|
+
证书领域模型引擎包括证书认证的模型。|
|
567
|
+
|unidom-contact|200103DDHHMMSS|Contact Subscription, Email Address|The Contact domain model engine includes the Contact Subscription and Email Address models. 联系方式领域模型引擎包括联系方式订阅和电子邮箱地址的模型。|
|
568
|
+
|unidom-geo|200104DDHHMMSS|Location, Locating|The Geo domain model engine includes the Location and Locating models. 地理领域模型引擎包括位置和定位的模型。|
|
569
|
+
|unidom-article_number|200201DDHHMMSS|Marking, EAN 13 Barcode, EAN 8 Barcode|The Article Number domain model engine includes Marking, EAN-13, and EAN-8 models. 物品编码领域模型引擎包括打码、EAN-13和EAN-8的模型。|
|
570
|
+
|unidom-product|200202DDHHMMSS|Product, Product Associating|The Product domain model engine includes Product and Produt Associating models. 产品领域模型引擎包括产品和产品关联的模型。|
|
571
|
+
|unidom-price|200203DDHHMMSS|Price|The Price domain model engine includes Price and its relative models. 价格领域模型引擎包括定价及其相关的模型。|
|
572
|
+
|unidom-shopping|200205DDHHMMSS|Shopping Cart, Shopping Item|The Shopping domain model engine includes Shopping Cart and Shopping Item models. 购物领域模型引擎包括购物车和购物项的模型。|
|
573
|
+
|unidom-order|200206DDHHMMSS|Order, Order Item, Order Adjustment|The Order domain model engine includes Order, Order Item, and Order Adjustment models. 订单领域模型引擎包括订单、订单项和订单调整的模型。|
|
574
|
+
|unidom-inventory|200209DDHHMMSS|Serialized Inventory Item, Grouped Inventory Item, Lot, Inventory Item Variance|The Inventory domain model engine includes the Serialized Inventory Item, the Grouped Inventory Item, the Lot, and the Inventory Item Variance models. 库存领域模型引擎包括序列化库存项、分组库存项、批量和库存项变化的模型。|
|
575
|
+
|unidom-shipment|200210DDHHMMSS|Shipment, Shipment Item, Shipment Package, Shipment Package Item, Shipment Receipt|The Shipment domain model engine includes the Shipment, Shipment Item, Shipment Package, Shipment Package Item, and Shipment Receipt model. 装运领域模型引擎包括装运、装运项、装运包裹、装运包裹项、装运收据的模型。|
|
576
|
+
|unidom-position|200402DDHHMMSS|Occupation, Position, Post, Position Reporting Structure|The Position domain model engine includes the Occupation, Position, Post, and Position Reporting Structure models.
|
577
|
+
职位领域模型引擎包括职业、职位、岗位及岗位报告关系模型。|
|
578
|
+
|unidom-accession|200405DDHHMMSS|Post Fulfillment|The Accession domain model engine includes the Post Fulfillment and its relative models. 就职领域模型引擎包括岗位履行及其相关的模型。|
|
579
|
+
|unidom-stapar|200601DDHHMMSS|Sample, Matching|The Statistical Approach of Pattern Recognition domain model engine includes the Sample and Matching and its relative models. 统计模式识别领域模型引擎包括采样、匹配的模型。|
|
580
|
+
|
818
581
|
|
819
582
|
### Country Extensions (200YMM9NNNMMSS)
|
820
583
|
|
@@ -41,7 +41,7 @@ module Unidom::Common::Concerns::Aes256Cryptor
|
|
41
41
|
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
class_methods do
|
45
45
|
|
46
46
|
def encryption_algorithm
|
47
47
|
'AES-256-CBC'
|
@@ -60,7 +60,9 @@ module Unidom::Common::Concerns::Aes256Cryptor
|
|
60
60
|
cipher = OpenSSL::Cipher::AES.new(256, 'CBC')
|
61
61
|
cipher.encrypt
|
62
62
|
cipher.padding = aes_256_padding
|
63
|
-
|
63
|
+
|
64
|
+
times = key.length/cipher.key_len>=1 ? 1 : cipher.key_len/key.length+1
|
65
|
+
cipher.key = (key*times)[0..cipher.key_len-1]
|
64
66
|
|
65
67
|
cipher.update(message)+cipher.final
|
66
68
|
|
@@ -77,7 +79,10 @@ module Unidom::Common::Concerns::Aes256Cryptor
|
|
77
79
|
cipher = OpenSSL::Cipher::AES.new(256, 'CBC')
|
78
80
|
cipher.decrypt
|
79
81
|
cipher.padding = aes_256_padding
|
80
|
-
cipher.key = key
|
82
|
+
#cipher.key = key
|
83
|
+
|
84
|
+
times = key.length/cipher.key_len>=1 ? 1 : cipher.key_len/key.length+1
|
85
|
+
cipher.key = (key*times)[0..cipher.key_len-1]
|
81
86
|
|
82
87
|
cipher.update(encoded)+cipher.final
|
83
88
|
|
@@ -140,6 +140,19 @@ module Unidom::Common::Concerns::ModelExtension
|
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
+
##
|
144
|
+
# 抽取验证错误。
|
145
|
+
def extract_errors
|
146
|
+
refined_errors = {}
|
147
|
+
self.errors.messages.each do | name, messages |
|
148
|
+
details = errors.details[name]
|
149
|
+
refined_errors[name] = []
|
150
|
+
messages.count.times { |i| refined_errors[name] << details[i].merge(message: messages[i]) }
|
151
|
+
end
|
152
|
+
refined_errors
|
153
|
+
end
|
154
|
+
|
155
|
+
|
143
156
|
end
|
144
157
|
|
145
158
|
module ClassMethods
|
@@ -1,38 +1,44 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# .enable_initializer 方法简化了知识层枚举和数据库迁移脚本的加载。
|
4
|
-
|
5
|
-
module Unidom::Common::EngineExtension
|
6
|
-
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
#included do |includer|
|
10
|
-
#end
|
11
|
-
|
12
|
-
module ClassMethods
|
1
|
+
module Unidom
|
2
|
+
module Common
|
13
3
|
|
14
4
|
##
|
15
|
-
#
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
5
|
+
# Engine Extension 是为 Rails 引擎提供的扩展关注点。
|
6
|
+
# .enable_initializer 方法简化了知识层枚举和数据库迁移脚本的加载。
|
7
|
+
module EngineExtension
|
8
|
+
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
#included do |includer|
|
12
|
+
#end
|
13
|
+
|
14
|
+
#module ClassMethods
|
15
|
+
class_methods do
|
16
|
+
|
17
|
+
##
|
18
|
+
# 设置初始化器的开关。如:
|
19
|
+
# Unidom::Common::EngineExtension.enable_initializer enum_enabled: true, migration_enabled: false
|
20
|
+
# enum_enabled 表明是否加载枚举型。
|
21
|
+
# migration_enabled 表明是否运行领域模型数据库迁移脚本,同时也表明加载对应的领域模型。
|
22
|
+
def enable_initializer(enum_enabled: false, migration_enabled: false)
|
23
|
+
|
24
|
+
if enum_enabled
|
25
|
+
require 'unidom/common/yaml_helper'
|
26
|
+
initializer :load_config_initializers do |app|
|
27
|
+
Unidom::Common::YamlHelper.load_enum config: app.config, root: config.root
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if migration_enabled
|
32
|
+
initializer :append_migrations do |app|
|
33
|
+
config.paths['db/migrate'].expanded.each { |expanded_path| app.config.paths['db/migrate'] << expanded_path } unless Unidom::Common::Neglection.namespace_neglected?(self.class.name)||app.root.to_s.match(root.to_s)
|
34
|
+
end
|
35
|
+
end
|
27
36
|
|
28
|
-
if migration_enabled
|
29
|
-
initializer :append_migrations do |app|
|
30
|
-
config.paths['db/migrate'].expanded.each { |expanded_path| app.config.paths['db/migrate'] << expanded_path } unless Unidom::Common::Neglection.namespace_neglected?(self.class.name)||app.root.to_s.match(root.to_s)
|
31
37
|
end
|
38
|
+
|
32
39
|
end
|
33
40
|
|
34
41
|
end
|
35
42
|
|
36
43
|
end
|
37
|
-
|
38
44
|
end
|
@@ -1,20 +1,25 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Unidom
|
2
|
+
module Common
|
3
3
|
|
4
|
-
|
4
|
+
##
|
5
|
+
# Neglection 根据配置信息忽略指定的类或者命名空间。
|
6
|
+
class Neglection
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
8
|
+
##
|
9
|
+
# 判断指定的类名是否被忽略。如:
|
10
|
+
# Unidom::Common::Neglection.namespace_neglected? 'Namespace::ClassName'
|
11
|
+
# 在应用的 config/initializers/unidom.rb 文件中配置如下代码,即可忽略 Namespace::ClassName 这个类。
|
12
|
+
# Unidom::Common.configure do |options|
|
13
|
+
# # The migrations inside the following namespaces will be ignored. The models inside the following namespaces won't be defined.
|
14
|
+
# options[:neglected_namespaces] = %w{
|
15
|
+
# Namespace::ClassName
|
16
|
+
# }
|
17
|
+
def self.namespace_neglected?(class_name)
|
18
|
+
neglected_namespaces = Unidom::Common.try(:options).try(:[], :neglected_namespaces)
|
19
|
+
neglected_namespaces.present? ? neglected_namespaces.include?(class_name.to_s.deconstantize) : false
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
19
23
|
|
24
|
+
end
|
20
25
|
end
|
@@ -1,20 +1,25 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Unidom
|
2
|
+
module Common
|
3
3
|
|
4
|
-
|
4
|
+
##
|
5
|
+
# Numeration 是数字格式转换的辅助类。
|
6
|
+
class Numeration
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
##
|
9
|
+
# 将二进制数据转换成 16 进制的表达。如:
|
10
|
+
# Unidom::Common::Numeration.hex [ 'A', '}' ]
|
11
|
+
def self.hex(data)
|
12
|
+
data.present? ? data.unpack('H*')[0] : nil
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
##
|
16
|
+
# 将十六进制数的表达字符串,转换成二进制数据。如:
|
17
|
+
# Unidom::Common::Numeration.rev_hex '6CA0'
|
18
|
+
def self.rev_hex(hex)
|
19
|
+
hex.present? ? hex.scan(/../).map(&:hex).pack('c*') : nil
|
20
|
+
end
|
19
21
|
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
20
25
|
end
|
@@ -1,25 +1,30 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Unidom
|
2
|
+
module Common
|
3
3
|
|
4
|
-
|
4
|
+
##
|
5
|
+
# YAML Helper 是用于加载知识层枚举的配置文件的辅助模块。
|
6
|
+
module YamlHelper
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
8
|
+
##
|
9
|
+
# 从应用或者引擎的跟路径 root 加载 config/enum.yml 中的内容到 config 中。
|
10
|
+
def self.load_enum(config: nil, root: nil)
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
+
enum_yaml_path = root.join 'config', 'enum.yml'
|
13
|
+
raise ArgumentError.new "The file #{enum_yaml_path} does not exist." unless enum_yaml_path.exist?
|
14
|
+
|
15
|
+
unless config.respond_to? :enum
|
16
|
+
config.class_eval do
|
17
|
+
attr_accessor :enum
|
18
|
+
end
|
19
|
+
end
|
20
|
+
config.enum = {} if config.enum.nil?
|
21
|
+
|
22
|
+
enum_definitions = YAML.load File.read(enum_yaml_path)
|
23
|
+
config.enum.merge! enum_definitions['enum'] if enum_definitions.present?&&enum_definitions['enum'].present?
|
12
24
|
|
13
|
-
unless config.respond_to? :enum
|
14
|
-
config.class_eval do
|
15
|
-
attr_accessor :enum
|
16
25
|
end
|
17
|
-
end
|
18
|
-
config.enum = {} if config.enum.nil?
|
19
26
|
|
20
|
-
|
21
|
-
config.enum.merge! enum_definitions['enum'] if enum_definitions.present?&&enum_definitions['enum'].present?
|
27
|
+
end
|
22
28
|
|
23
29
|
end
|
24
|
-
|
25
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unidom-common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '3.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '7.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '7.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pg
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,11 +124,11 @@ files:
|
|
124
124
|
- lib/unidom/common/numeration.rb
|
125
125
|
- lib/unidom/common/version.rb
|
126
126
|
- lib/unidom/common/yaml_helper.rb
|
127
|
-
homepage:
|
127
|
+
homepage: https://gitee.com/Unidom/unidom-common
|
128
128
|
licenses:
|
129
129
|
- MIT
|
130
130
|
metadata: {}
|
131
|
-
post_install_message:
|
131
|
+
post_install_message:
|
132
132
|
rdoc_options: []
|
133
133
|
require_paths:
|
134
134
|
- lib
|
@@ -143,8 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
147
|
-
signing_key:
|
146
|
+
rubygems_version: 3.5.6
|
147
|
+
signing_key:
|
148
148
|
specification_version: 4
|
149
149
|
summary: Unidom Common Domain Model Engine 常用领域模型引擎
|
150
150
|
test_files: []
|