unidom-common 2.1.2 → 3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c086fb6689c4136771a0168f4532b7e8532de09716682d9a8747379056ef30ef
4
- data.tar.gz: deb216901a9121e91189982b5f4db8d2a2a9e275df2bf8dd88f8effa4b5279ad
3
+ metadata.gz: 9c71146870a9030fc64208ac28ed4bc6f7a92530432a95ffcbb5166d13ad7527
4
+ data.tar.gz: b045e9c5680d646c078d9b6b16e1ecac57f6b4b5db15c48b37e0158919ef5141
5
5
  SHA512:
6
- metadata.gz: 8ee211251ac52e8116f708710a3514cdba6cc65b8e12dbc987b0465cc1e620a3bc7c24d1803a50176fb9adeff4765d661237b500bb8ba029d64f20394ca1e787
7
- data.tar.gz: ddda1c685bf861c47ed23c20bd1815e8c1059191abf35bf505c6e544fa9ec5fdb7b6c7da72bea4ac54df2e371975de80cdde3a4169197d56874d8ee363899f3e
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[5.0]
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[5.0]
192
+ class CreateOrderings < ActiveRecord::Migration[6.0]
193
193
 
194
194
  def change
195
195
 
@@ -79,7 +79,10 @@ module Unidom::Common::Concerns::Aes256Cryptor
79
79
  cipher = OpenSSL::Cipher::AES.new(256, 'CBC')
80
80
  cipher.decrypt
81
81
  cipher.padding = aes_256_padding
82
- 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]
83
86
 
84
87
  cipher.update(encoded)+cipher.final
85
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
- # Engine Extension 是为 Rails 引擎提供的扩展关注点。
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
- # Unidom::Common::EngineExtension.enable_initializer enum_enabled: true, migration_enabled: false
17
- # enum_enabled 表明是否加载枚举型。
18
- # migration_enabled 表明是否运行领域模型数据库迁移脚本,同时也表明加载对应的领域模型。
19
- def enable_initializer(enum_enabled: false, migration_enabled: false)
20
-
21
- if enum_enabled
22
- require 'unidom/common/yaml_helper'
23
- initializer :load_config_initializers do |app|
24
- Unidom::Common::YamlHelper.load_enum config: app.config, root: config.root
25
- end
26
- end
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
- # Neglection 根据配置信息忽略指定的类或者命名空间。
1
+ module Unidom
2
+ module Common
3
3
 
4
- class Unidom::Common::Neglection
4
+ ##
5
+ # Neglection 根据配置信息忽略指定的类或者命名空间。
6
+ class Neglection
5
7
 
6
- ##
7
- # 判断指定的类名是否被忽略。如:
8
- # Unidom::Common::Neglection.namespace_neglected? 'Namespace::ClassName'
9
- # 在应用的 config/initializers/unidom.rb 文件中配置如下代码,即可忽略 Namespace::ClassName 这个类。
10
- # Unidom::Common.configure do |options|
11
- # # The migrations inside the following namespaces will be ignored. The models inside the following namespaces won't be defined.
12
- # options[:neglected_namespaces] = %w{
13
- # Namespace::ClassName
14
- # }
15
- def self.namespace_neglected?(class_name)
16
- neglected_namespaces = Unidom::Common.try(:options).try(:[], :neglected_namespaces)
17
- neglected_namespaces.present? ? neglected_namespaces.include?(class_name.to_s.deconstantize) : false
18
- end
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
- # Numeration 是数字格式转换的辅助类。
1
+ module Unidom
2
+ module Common
3
3
 
4
- class Unidom::Common::Numeration
4
+ ##
5
+ # Numeration 是数字格式转换的辅助类。
6
+ class Numeration
5
7
 
6
- ##
7
- # 将二进制数据转换成 16 进制的表达。如:
8
- # Unidom::Common::Numeration.hex [ 'A', '}' ]
9
- def self.hex(data)
10
- data.present? ? data.unpack('H*')[0] : nil
11
- end
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
- # Unidom::Common::Numeration.rev_hex '6CA0'
16
- def self.rev_hex(hex)
17
- hex.present? ? hex.scan(/../).map(&:hex).pack('c*') : nil
18
- end
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,5 +1,5 @@
1
1
  module Unidom
2
2
  module Common
3
- VERSION = '2.1.2'.freeze
3
+ VERSION = '3.0'.freeze
4
4
  end
5
5
  end
@@ -1,25 +1,30 @@
1
- ##
2
- # YAML Helper 是用于加载知识层枚举的配置文件的辅助模块。
1
+ module Unidom
2
+ module Common
3
3
 
4
- module Unidom::Common::YamlHelper
4
+ ##
5
+ # YAML Helper 是用于加载知识层枚举的配置文件的辅助模块。
6
+ module YamlHelper
5
7
 
6
- ##
7
- # 从应用或者引擎的跟路径 root 加载 config/enum.yml 中的内容到 config 中。
8
- def self.load_enum(config: nil, root: nil)
8
+ ##
9
+ # 从应用或者引擎的跟路径 root 加载 config/enum.yml 中的内容到 config 中。
10
+ def self.load_enum(config: nil, root: nil)
9
11
 
10
- enum_yaml_path = root.join 'config', 'enum.yml'
11
- raise ArgumentError.new "The file #{enum_yaml_path} does not exist." unless enum_yaml_path.exist?
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
- enum_definitions = YAML.load File.read(enum_yaml_path)
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: 2.1.2
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: 2020-05-07 00:00:00.000000000 Z
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: '6.0'
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: '6.0'
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: '1.0'
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: '1.0'
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: http://github.com/topbitdu/unidom-common
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.1.2
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: []