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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bd08cfd199d4f29c2097191bf24f73d3291aae1
4
- data.tar.gz: 566e2ee9e74cbb4faf9b2e63bc7e6fd3ffea75cf
3
+ metadata.gz: 4a55892117ff845f398d300492f2cfa3a4667830
4
+ data.tar.gz: a29d4636705703f4ebc6be67f4bfe6699310e606
5
5
  SHA512:
6
- metadata.gz: 05ec87e12d971df5e1ff1ab7680375af71b0476a134d05f71f64a6eea713713fb0ef009e47da54a2169fea3febe384cf26b19623a3c0fe44e69226b4918f62c6
7
- data.tar.gz: 4c8ae78ce001e40575d426621164b0871d34eed2310e031cda53ccb7355713a9285735b5d38fb7b8ef4028510ca1b924f635441d37055c5f3e87c7f2eb82c288
6
+ metadata.gz: f5090d419d1f2ecc3d3dc55d00a6a2d05cd032447ba8f9844e9e6437183e72de130ac1d04fdbc6d088cc827188048c6426d713d41ca91d54a61b0aa8467df86a
7
+ data.tar.gz: 4249e11d7d7e2e3a4e8d4a8f81360f167408f7690ea3f5f5c7370becd4c71f954081c8a06401ce718735e57bff7750a74c40f5558d6cbd63cdea0189874838bc
@@ -1,3 +1,6 @@
1
+ ##
2
+ # Application controller 是模块内所有控制器的基类。
3
+
1
4
  class Unidom::Common::ApplicationController < ActionController::Base
2
5
  protect_from_forgery with: :exception
3
6
  end
@@ -1,2 +1,5 @@
1
+ ##
2
+ # Application job 是模块内所有异步任务的基类。
3
+
1
4
  class Unidom::Common::ApplicationJob < ActiveJob::Base
2
5
  end
@@ -1,3 +1,6 @@
1
+ ##
2
+ # Application mailer 是模块内所有电子邮件发送类的基类。
3
+
1
4
  class Unidom::Common::ApplicationMailer < ActionMailer::Base
2
5
  default from: 'from@example.com'
3
6
  layout 'mailer'
@@ -1,3 +1,6 @@
1
+ ##
2
+ # Application record 是模块内所有模型的抽象基类。
3
+
1
4
  class Unidom::Common::ApplicationRecord < ActiveRecord::Base
2
5
  self.abstract_class = true
3
6
  end
@@ -1,3 +1,6 @@
1
+ ##
2
+ # MD-5 Digester 基于 MD-5 算法的摘要逻辑关注点。
3
+
1
4
  module Unidom::Common::Concerns::Md5Digester
2
5
 
3
6
  extend ActiveSupport::Concern
@@ -1,3 +1,6 @@
1
+ ##
2
+ # SHA-1 Digester 基于 SHA-1 算法的摘要逻辑关注点。
3
+
1
4
  module Unidom::Common::Concerns::Sha1Digester
2
5
 
3
6
  extend ActiveSupport::Concern
@@ -1,3 +1,6 @@
1
+ ##
2
+ # SHA-256 Digester 基于 SHA-256 算法的摘要逻辑关注点。
3
+
1
4
  module Unidom::Common::Concerns::Sha256Digester
2
5
 
3
6
  extend ActiveSupport::Concern
@@ -1,3 +1,6 @@
1
+ ##
2
+ # SHA-2 Digester 基于 SHA-2 算法的摘要逻辑关注点。
3
+
1
4
  module Unidom::Common::Concerns::Sha2Digester
2
5
 
3
6
  extend ActiveSupport::Concern
@@ -1,3 +1,6 @@
1
+ ##
2
+ # SHA-384 Digester 基于 SHA-384 算法的摘要逻辑关注点。
3
+
1
4
  module Unidom::Common::Concerns::Sha384Digester
2
5
 
3
6
  extend ActiveSupport::Concern
@@ -1,3 +1,6 @@
1
+ ##
2
+ # SHA-512 Digester 基于 SHA-512 算法的摘要逻辑关注点。
3
+
1
4
  module Unidom::Common::Concerns::Sha512Digester
2
5
 
3
6
  extend ActiveSupport::Concern
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Common
3
- VERSION = '1.9.1'.freeze
3
+ VERSION = '1.9.2'.freeze
4
4
  end
5
5
  end
@@ -3,6 +3,8 @@
3
3
 
4
4
  module Unidom::Common::YamlHelper
5
5
 
6
+ ##
7
+ # 从应用或者引擎的跟路径 root 加载 config/enum.yml 中的内容到 config 中。
6
8
  def self.load_enum(config: nil, root: nil)
7
9
 
8
10
  enum_yaml_path = root.join 'config', 'enum.yml'
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.1
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-01-26 00:00:00.000000000 Z
11
+ date: 2017-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails