unidom-common 1.9.1 → 1.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/unidom/common/application_controller.rb +3 -0
- data/app/jobs/unidom/common/application_job.rb +3 -0
- data/app/mailers/unidom/common/application_mailer.rb +3 -0
- data/app/models/unidom/common/application_record.rb +3 -0
- data/app/models/unidom/common/concerns/md5_digester.rb +3 -0
- data/app/models/unidom/common/concerns/sha1_digester.rb +3 -0
- data/app/models/unidom/common/concerns/sha256_digester.rb +3 -0
- data/app/models/unidom/common/concerns/sha2_digester.rb +3 -0
- data/app/models/unidom/common/concerns/sha384_digester.rb +3 -0
- data/app/models/unidom/common/concerns/sha512_digester.rb +3 -0
- data/lib/unidom/common/data_helper.rb +10 -0
- data/lib/unidom/common/engine_extension.rb +5 -0
- data/lib/unidom/common/neglection.rb +13 -1
- data/lib/unidom/common/numeration.rb +6 -0
- data/lib/unidom/common/version.rb +1 -1
- data/lib/unidom/common/yaml_helper.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a55892117ff845f398d300492f2cfa3a4667830
|
4
|
+
data.tar.gz: a29d4636705703f4ebc6be67f4bfe6699310e606
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5090d419d1f2ecc3d3dc55d00a6a2d05cd032447ba8f9844e9e6437183e72de130ac1d04fdbc6d088cc827188048c6426d713d41ca91d54a61b0aa8467df86a
|
7
|
+
data.tar.gz: 4249e11d7d7e2e3a4e8d4a8f81360f167408f7690ea3f5f5c7370becd4c71f954081c8a06401ce718735e57bff7750a74c40f5558d6cbd63cdea0189874838bc
|
@@ -5,6 +5,11 @@ module Unidom
|
|
5
5
|
|
6
6
|
module DataHelper
|
7
7
|
|
8
|
+
##
|
9
|
+
# 以 CSV 的格式加载 file_name 对应的文件,利用闭包遍历每一行。如:
|
10
|
+
# Unidom::Common::DataHelper.each_csv_row '/var/file.csv' do |line|
|
11
|
+
# puts line.inspect
|
12
|
+
# end
|
8
13
|
def each_csv_row(file_name, &block)
|
9
14
|
|
10
15
|
started_at = Time.now
|
@@ -21,6 +26,11 @@ module Unidom
|
|
21
26
|
|
22
27
|
end
|
23
28
|
|
29
|
+
##
|
30
|
+
# 根据日期文本 date_text 解析出时间,如果日期文本为空,则返回指定的时间或当前时间。如:
|
31
|
+
# Unidom::Common::DataHelper.parse_time '2000-01-01' # 2000-01-01 00:00:00
|
32
|
+
# Unidom::Common::DataHelper.parse_time '' # Time.now
|
33
|
+
# Unidom::Common::DataHelper.parse_time nil, Time.now-1.minute # Time.now-1.minute
|
24
34
|
def parse_time(date_text, default = Time.now)
|
25
35
|
return default if date_text.blank?
|
26
36
|
date = Date.parse date_text
|
@@ -11,6 +11,11 @@ module Unidom::Common::EngineExtension
|
|
11
11
|
|
12
12
|
module ClassMethods
|
13
13
|
|
14
|
+
##
|
15
|
+
# 设置初始化器的开关。如:
|
16
|
+
# Unidom::Common::EngineExtension.enable_initializer enum_enabled: true, migration_enabled: false
|
17
|
+
# enum_enabled 表明是否加载枚举型。
|
18
|
+
# migration_enabled 表明是否运行领域模型数据库迁移脚本,同时也表明加载对应的领域模型。
|
14
19
|
def enable_initializer(enum_enabled: false, migration_enabled: false)
|
15
20
|
|
16
21
|
if enum_enabled
|
@@ -1,7 +1,19 @@
|
|
1
|
+
##
|
2
|
+
# Neglection 根据配置信息忽略指定的类或者命名空间。
|
3
|
+
|
1
4
|
class Unidom::Common::Neglection
|
2
5
|
|
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
|
+
# }
|
3
15
|
def self.namespace_neglected?(class_name)
|
4
|
-
neglected_namespaces = Unidom::Common.options[:neglected_namespaces
|
16
|
+
neglected_namespaces = Unidom::Common.try(:options).try(:[], :neglected_namespaces)
|
5
17
|
neglected_namespaces.present? ? neglected_namespaces.include?(class_name.to_s.deconstantize) : false
|
6
18
|
end
|
7
19
|
|
@@ -3,10 +3,16 @@
|
|
3
3
|
|
4
4
|
class Unidom::Common::Numeration
|
5
5
|
|
6
|
+
##
|
7
|
+
# 将二进制数据转换成 16 进制的表达。如:
|
8
|
+
# Unidom::Common::Numeration.hex [ 'A', '}' ]
|
6
9
|
def self.hex(data)
|
7
10
|
data.present? ? data.unpack('H*')[0] : nil
|
8
11
|
end
|
9
12
|
|
13
|
+
##
|
14
|
+
# 将十六进制数的表达字符串,转换成二进制数据。如:
|
15
|
+
# Unidom::Common::Numeration.rev_hex '6CA0'
|
10
16
|
def self.rev_hex(hex)
|
11
17
|
hex.present? ? hex.scan(/../).map(&:hex).pack('c*') : nil
|
12
18
|
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: 1.9.
|
4
|
+
version: 1.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|