unidom-common 1.2 → 1.3

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: 88c40a102845260fbe5699f42e6d5c2735ffa0c0
4
- data.tar.gz: 47f31fb4af3d8fb94cd73568399293dd6c0ebbe8
3
+ metadata.gz: 72b239e03d003ae2a4e0f68db103b014417ea67e
4
+ data.tar.gz: 24dc122ec9aa546cbbe8565eab0bd56ace09a143
5
5
  SHA512:
6
- metadata.gz: 3e326b1f17168a898d71f72e2fd2f642d67c85cb8ddaa132a6abd28ff25c1a1a51b0cb3c016d32c630abc151d254c360cc2185004a572ff22309855cc8ad10af
7
- data.tar.gz: 9c65b56a55eb3184101a42ead4afaca5b9c0fd0d67b8975ed469fc1f506d5776578c6f213b7423c5135b72920eaf5d00f8a286c8fbd976d47ad6007c8282d851
6
+ metadata.gz: d0ee19de3aaff418f90faf82cd2cf56e7dee37d42907057317161712d1f76ce7d06aa17321121ed9e22fbc817a3fb06bebc1b0342560c10cf669fd805e6f3a1d
7
+ data.tar.gz: b833df4e2a8e3efd2654ab64a379bcf0dd9ac1bbf4c99f6b4724fcdd89a5f3a7c9c78a27faa7bbb2400f34f20c329dd09196c56ff85f8f705f4c0eda3af07d1d
data/README.md CHANGED
@@ -235,6 +235,62 @@ hex_digested == Unidom::Common::Numeration.hex digested # true
235
235
  ```
236
236
 
237
237
 
238
+ ## SHA 1 Digester
239
+ ```ruby
240
+ class IdentityCard
241
+
242
+ include Unidom::Common::Concerns::Sha1Digester
243
+ attr_accessor :identification_number
244
+
245
+ def initialize(identification_number)
246
+ self.identification_number = identification_number
247
+ end
248
+
249
+ def digest_identification_number
250
+ digest identification_number, pepper: self.class.name
251
+ end
252
+
253
+ def hex_digest_identification_number
254
+ hex_digest identification_number, pepper: self.class.name
255
+ end
256
+
257
+ end
258
+
259
+ identity_card = IdentityCard.new '9527'
260
+ digested = identity_card.digest_identification_number
261
+ hex_digested = identity_card.hex_digest_identification_number
262
+ hex_digested == Unidom::Common::Numeration.hex digested # true
263
+ ```
264
+
265
+
266
+ ## SHA 2 Digester
267
+ ```ruby
268
+ class IdentityCard
269
+
270
+ include Unidom::Common::Concerns::Sha1Digester
271
+ attr_accessor :identification_number
272
+
273
+ def initialize(identification_number)
274
+ self.identification_number = identification_number
275
+ end
276
+
277
+ def digest_identification_number
278
+ digest identification_number, pepper: self.class.name
279
+ end
280
+
281
+ def hex_digest_identification_number
282
+ hex_digest identification_number, pepper: self.class.name
283
+ end
284
+
285
+ end
286
+
287
+ identity_card = IdentityCard.new '9527'
288
+ digested = identity_card.digest_identification_number
289
+ hex_digested = identity_card.hex_digest_identification_number
290
+ hex_digested == Unidom::Common::Numeration.hex digested # true
291
+ ```
292
+
293
+
238
294
  ## ActiveRecord Migration Naming Convention
239
295
  ### Domain Models (200YMMDDHHMMSS)
240
296
 
@@ -305,6 +361,7 @@ hex_digested == Unidom::Common::Numeration.hex digested # true
305
361
  <td>The Standard domain model engine includes the Standard model and the Standard Associating model. 标准领域模型引擎包括行为标准和标准关联的模型。</td>
306
362
  </tr>
307
363
 
364
+
308
365
  <tr>
309
366
  <td>[![unidom-party](https://badge.fury.io/rb/unidom-party.svg)](https://github.com/topbitdu/unidom-party)</td>
310
367
  <td>200101DDHHMMSS</td>
@@ -348,6 +405,7 @@ hex_digested == Unidom::Common::Numeration.hex digested # true
348
405
  <td>The Geo domain model engine includes the Location and Locating models. 地理领域模型引擎包括位置和定位的模型。</td>
349
406
  </tr>
350
407
 
408
+
351
409
  <tr>
352
410
  <td>[![unidom-article_number](https://badge.fury.io/rb/unidom-article_number.svg)](https://github.com/topbitdu/unidom-article_number)</td>
353
411
  <td>200201DDHHMMSS</td>
@@ -399,6 +457,19 @@ hex_digested == Unidom::Common::Numeration.hex digested # true
399
457
  <td>The Order domain model engine includes Order, Order Item, and Order Adjustment models. 订单领域模型引擎包括订单、订单项和订单调整的模型。</td>
400
458
  </tr>
401
459
 
460
+ <tr>
461
+ <td>[![unidom-inventory](https://badge.fury.io/rb/unidom-inventory.svg)](https://github.com/topbitdu/unidom-inventory)</td>
462
+ <td>200209DDHHMMSS</td>
463
+ <td>
464
+ - Serialized Inventory Item
465
+ - Grouped Inventory Item
466
+ - Lot
467
+ - Inventory Item Variance
468
+ </td>
469
+ <td>The Inventory domain model engine includes the Serialized Inventory Item, the Grouped Inventory Item, the Lot, and the Inventory Item Variance models. 库存领域模型引擎包括序列化库存项、分组库存项、批量和库存项变化的模型。</td>
470
+ </tr>
471
+
472
+
402
473
  <tr>
403
474
  <td>[![unidom-position](https://badge.fury.io/rb/unidom-position.svg)](https://github.com/topbitdu/unidom-position)</td>
404
475
  <td>200402DDHHMMSS</td>
@@ -421,6 +492,7 @@ hex_digested == Unidom::Common::Numeration.hex digested # true
421
492
  <td>The Position domain model engine includes the Post Fulfillment and its relative models. 就职领域模型引擎包括岗位履行及其相关的模型。</td>
422
493
  </tr>
423
494
 
495
+
424
496
  </tbody>
425
497
  </table>
426
498
 
@@ -4,6 +4,30 @@ module Unidom::Common::Concerns::Aes256Cryptor
4
4
 
5
5
  included do |includer|
6
6
 
7
+ def encrypt(message, key: nil)
8
+ self.class.encrypt message, key: key
9
+ end
10
+
11
+ def decrypt(encoded, key: nil)
12
+ self.class.decrypt encoded, key: key
13
+ end
14
+
15
+ def aes_256_padding
16
+ self.class.aes_256_padding
17
+ end
18
+
19
+ def hex_encrypt(message, key: nil)
20
+ self.class.hex_encrypt message, key: key
21
+ end
22
+
23
+ def hex_decrypt(encoded, key: nil)
24
+ self.class.hex_decrypt encoded, key: key
25
+ end
26
+
27
+ end
28
+
29
+ module ClassMethods
30
+
7
31
  def encrypt(message, key: nil)
8
32
 
9
33
  raise ArgumentError.new('The message argument is required.') if message.blank?
@@ -1,186 +1,179 @@
1
- module Unidom
2
- module Common
3
- module Concerns
1
+ module Unidom::Common::Concerns::ModelExtension
4
2
 
5
- module ModelExtension
3
+ extend ActiveSupport::Concern
6
4
 
7
- extend ActiveSupport::Concern
5
+ included do |includer|
8
6
 
9
- included do |includer|
7
+ validates :state, presence: true, length: { is: columns_hash['state'].limit }
10
8
 
11
- validates :state, presence: true, length: { is: columns_hash['state'].limit }
9
+ scope :included_by, ->(inclusion) { where id: inclusion }
10
+ scope :excluded_by, ->(exclusion) { where.not id: exclusion }
12
11
 
13
- scope :included_by, ->(inclusion) { where id: inclusion }
14
- scope :excluded_by, ->(exclusion) { where.not id: exclusion }
12
+ scope :transited_to, ->(states) { where state: states }
15
13
 
16
- scope :transited_to, ->(states) { where state: states }
14
+ scope :valid_at, ->(now: Time.now) { where "? BETWEEN #{includer.table_name}.opened_at AND #{includer.table_name}.closed_at", now }
15
+ scope :valid_duration, ->(range) { where "(#{includer.table_name}.opened_at BETWEEN ? AND ?) OR (#{includer.table_name}.closed_at <= ? AND #{includer.table_name}.closed_at >= ?)", range.min, range.max, range.max, range.min }
17
16
 
18
- scope :valid_at, ->(now: Time.now) { where "? BETWEEN #{includer.table_name}.opened_at AND #{includer.table_name}.closed_at", now }
19
- scope :valid_duration, ->(range) { where "(#{includer.table_name}.opened_at BETWEEN ? AND ?) OR (#{includer.table_name}.closed_at <= ? AND #{includer.table_name}.closed_at >= ?)", range.min, range.max, range.max, range.min }
17
+ scope :alive, ->(living: true) { where defunct: !living }
18
+ scope :dead, ->(defunct: true) { where defunct: defunct }
20
19
 
21
- scope :alive, ->(living: true) { where defunct: !living }
22
- scope :dead, ->(defunct: true) { where defunct: defunct }
20
+ scope :notation_column_where, ->(name, operator, value) do
21
+ operation = :like==operator ? { operator: 'ILIKE', value: "%#{value}%" } : { operator: operator.to_s, value: value }
22
+ where "#{table_name}.notation -> 'columns' ->> '#{name}' #{operation[:operator]} :value", value: operation[:value]
23
+ end
23
24
 
24
- scope :notation_column_where, ->(name, operator, value) do
25
- operation = :like==operator ? { operator: 'ILIKE', value: "%#{value}%" } : { operator: operator.to_s, value: value }
26
- where "#{table_name}.notation -> 'columns' ->> '#{name}' #{operation[:operator]} :value", value: operation[:value]
27
- end
25
+ scope :notation_boolean_column_where, ->(name, value) do
26
+ where "(#{table_name}.notation -> 'columns' ->> '#{name}')::boolean = :value", value: (value ? true : false)
27
+ end
28
28
 
29
- scope :notation_boolean_column_where, ->(name, value) do
30
- where "(#{table_name}.notation -> 'columns' ->> '#{name}')::boolean = :value", value: (value ? true : false)
31
- end
29
+ if columns_hash['ordinal'].present?&&:integer==columns_hash['ordinal'].type
30
+ validates :ordinal, presence: true, numericality: { integer_only: true, greater_than: 0 }
31
+ scope :ordinal_is, ->(ordinal) { where ordinal: ordinal }
32
+ end
32
33
 
33
- if columns_hash['ordinal'].present?&&:integer==columns_hash['ordinal'].type
34
- validates :ordinal, presence: true, numericality: { integer_only: true, greater_than: 0 }
35
- scope :ordinal_is, ->(ordinal) { where ordinal: ordinal }
36
- end
34
+ if columns_hash['uuid'].present?&&:uuid==columns_hash['uuid'].type
35
+ validates :uuid, presence: true, length: { is: 36 }
36
+ scope :uuid_is, ->(uuid) { where uuid: uuid }
37
+ end
37
38
 
38
- if columns_hash['uuid'].present?&&:uuid==columns_hash['uuid'].type
39
- validates :uuid, presence: true, length: { is: 36 }
40
- scope :uuid_is, ->(uuid) { where uuid: uuid }
41
- end
39
+ if columns_hash['elemental'].present?&&:boolean==columns_hash['elemental'].type
40
+ scope :primary, ->(elemental = true) { where elemental: elemental }
41
+ end
42
42
 
43
- if columns_hash['elemental'].present?&&:boolean==columns_hash['elemental'].type
44
- scope :primary, ->(elemental = true) { where elemental: elemental }
45
- end
43
+ if columns_hash['grade'].present?&&:integer==columns_hash['grade'].type
44
+ validates :grade, presence: true, numericality: { integer_only: true, greater_than_or_equal_to: 0 }
45
+ scope :grade_is, ->(grade) { where grade: grade }
46
+ scope :grade_higher_than, ->(grade) { where "grade > :grade", grade: grade }
47
+ scope :grade_lower_than, ->(grade) { where "grade < :grade", grade: grade }
48
+ end
46
49
 
47
- if columns_hash['grade'].present?&&:integer==columns_hash['grade'].type
48
- validates :grade, presence: true, numericality: { integer_only: true, greater_than_or_equal_to: 0 }
49
- scope :grade_is, ->(grade) { where grade: grade }
50
- scope :grade_higher_than, ->(grade) { where "grade > :grade", grade: grade }
51
- scope :grade_lower_than, ->(grade) { where "grade < :grade", grade: grade }
52
- end
50
+ if columns_hash['priority'].present?&&:integer==columns_hash['priority'].type
51
+ validates :priority, presence: true, numericality: { integer_only: true, greater_than_or_equal_to: 0 }
52
+ scope :priority_is, ->(priority) { where priority: priority }
53
+ scope :priority_higher_than, ->(priority) { where "priority > :priority", priority: priority }
54
+ scope :priority_lower_than, ->(priority) { where "priority < :priority", priority: priority }
55
+ end
53
56
 
54
- if columns_hash['priority'].present?&&:integer==columns_hash['priority'].type
55
- validates :priority, presence: true, numericality: { integer_only: true, greater_than_or_equal_to: 0 }
56
- scope :priority_is, ->(priority) { where priority: priority }
57
- scope :priority_higher_than, ->(priority) { where "priority > :priority", priority: priority }
58
- scope :priority_lower_than, ->(priority) { where "priority < :priority", priority: priority }
59
- end
57
+ if columns_hash['slug'].present?&&:string==columns_hash['slug'].type
58
+ validates :slug, presence: true, length: { in: 1..columns_hash['slug'].limit }, uniqueness: true
59
+ scope :slug_is, ->(slug) { where slug: slug }
60
+ before_validation -> {
61
+ prefix = build_slug.to_s[0..(self.class.columns_hash['slug'].limit-37)]
62
+ unique = prefix
63
+ while includer.slug_is(unique).count>0
64
+ unique = "#{prefix}-#{::SecureRandom.uuid}"
65
+ end
66
+ self.slug = unique
67
+ }, on: :create
68
+ # on update: re-generate the slug if the slug was assigned to empty.
69
+ # to_query: escape characters
70
+ end
60
71
 
61
- if columns_hash['slug'].present?&&:string==columns_hash['slug'].type
62
- validates :slug, presence: true, length: { in: 1..columns_hash['slug'].limit }, uniqueness: true
63
- scope :slug_is, ->(slug) { where slug: slug }
64
- before_validation -> {
65
- prefix = build_slug.to_s[0..(self.class.columns_hash['slug'].limit-37)]
66
- unique = prefix
67
- while includer.slug_is(unique).count>0
68
- unique = "#{prefix}-#{::SecureRandom.uuid}"
69
- end
70
- self.slug = unique
71
- }, on: :create
72
- # on update: re-generate the slug if the slug was assigned to empty.
73
- # to_query: escape characters
74
- end
72
+ columns_hash.each do |column_name, hash|
75
73
 
76
- columns_hash.each do |column_name, hash|
77
-
78
- name = column_name.to_s
79
-
80
- if ('code'==name||name.ends_with?('_code'))&&:string==columns_hash[name].type
81
- class_eval do
82
- if columns_hash[name].null
83
- validates name.to_sym, allow_blank: true, length: { maximum: columns_hash[name].limit }
84
- scope "#{name}_length_is".to_sym, ->(length) { where "LENGTH(#{name}) = :length", length: length }
85
- elsif columns_hash[name].limit<=4
86
- validates name.to_sym, presence: true, length: { is: columns_hash[name].limit }
87
- else
88
- validates name.to_sym, presence: true, length: { maximum: columns_hash[name].limit }
89
- end
90
- scope "#{name}d_as".to_sym, ->(code) { where name => code }
91
- scope "not_#{name}d_as".to_sym, ->(code) { where.not name => code }
92
- scope "#{name}_starting_with".to_sym, ->(prefix) { where "#{name} LIKE :prefix", prefix: "#{prefix}%" }
93
- scope "#{name}_ending_with".to_sym, ->(suffix) { where "#{name} LIKE :suffix", suffix: "%#{suffix}" }
94
- end
95
- end
96
-
97
- if name.ends_with?('_at')&&:datetime==columns_hash[name].type
98
- matched = /\A(.+)_at\z/.match name
99
- class_eval do
100
- scope :"#{matched[1]}_on", ->(date) { where name => date.beginning_of_day..date.end_of_day }
101
- scope :"#{matched[1]}_during", ->(range) { where name => range }
102
- scope :"#{matched[1]}_before", ->(time) { where "#{table_name}.#{name} < :time", time: time }
103
- scope :"#{matched[1]}_not_after", ->(time) { where "#{table_name}.#{name} <= :time", time: time }
104
- scope :"#{matched[1]}_after", ->(time) { where "#{table_name}.#{name} > :time", time: time }
105
- scope :"#{matched[1]}_not_before", ->(time) { where "#{table_name}.#{name} >= :time", time: time }
106
- end
107
- end
108
-
109
- if name.ends_with?('_state')&&:string==columns_hash[name].type
110
- matched = /\A(.+)_state\z/.match name
111
- class_eval do
112
- scope :"#{matched[1]}_transited_to", ->(states) { where name => states }
113
- end
114
- end
74
+ name = column_name.to_s
115
75
 
76
+ if ('code'==name||name.ends_with?('_code'))&&:string==columns_hash[name].type
77
+ class_eval do
78
+ if columns_hash[name].null
79
+ validates name.to_sym, allow_blank: true, length: { maximum: columns_hash[name].limit }
80
+ scope "#{name}_length_is".to_sym, ->(length) { where "LENGTH(#{name}) = :length", length: length }
81
+ elsif columns_hash[name].limit<=4
82
+ validates name.to_sym, presence: true, length: { is: columns_hash[name].limit }
83
+ else
84
+ validates name.to_sym, presence: true, length: { maximum: columns_hash[name].limit }
116
85
  end
86
+ scope "#{name}d_as".to_sym, ->(code) { where name => code }
87
+ scope "not_#{name}d_as".to_sym, ->(code) { where.not name => code }
88
+ scope "#{name}_starting_with".to_sym, ->(prefix) { where "#{name} LIKE :prefix", prefix: "#{prefix}%" }
89
+ scope "#{name}_ending_with".to_sym, ->(suffix) { where "#{name} LIKE :suffix", suffix: "%#{suffix}" }
90
+ end
91
+ end
117
92
 
118
- includer.define_singleton_method :default_scope do
119
- includer.all.order("#{includer.table_name}.ordinal ASC") if includer.columns_hash['ordinal'].present?
120
- includer.all.order("#{includer.table_name}.created_at ASC")
121
- #relation = base.all
122
- #scopes.each do |s| relation = relation.send s.to_sym end
123
- #relation
124
- end
93
+ if name.ends_with?('_at')&&:datetime==columns_hash[name].type
94
+ matched = /\A(.+)_at\z/.match name
95
+ class_eval do
96
+ scope :"#{matched[1]}_on", ->(date) { where name => date.beginning_of_day..date.end_of_day }
97
+ scope :"#{matched[1]}_during", ->(range) { where name => range }
98
+ scope :"#{matched[1]}_before", ->(time) { where "#{table_name}.#{name} < :time", time: time }
99
+ scope :"#{matched[1]}_not_after", ->(time) { where "#{table_name}.#{name} <= :time", time: time }
100
+ scope :"#{matched[1]}_after", ->(time) { where "#{table_name}.#{name} > :time", time: time }
101
+ scope :"#{matched[1]}_not_before", ->(time) { where "#{table_name}.#{name} >= :time", time: time }
102
+ end
103
+ end
125
104
 
126
- def soft_destroy
127
- self.closed_at = Time.now
128
- self.defunct = true
129
- self.save
130
- end
105
+ if name.ends_with?('_state')&&:string==columns_hash[name].type
106
+ matched = /\A(.+)_state\z/.match name
107
+ class_eval do
108
+ validates name.to_sym, presence: true, length: { is: columns_hash[name].limit }
109
+ scope :"#{matched[1]}_transited_to", ->(states) { where name => states }
110
+ end
111
+ end
131
112
 
132
- def build_slug
133
- if respond_to? :name
134
- name
135
- elsif respond_to? :title
136
- title
137
- else
138
- ::SecureRandom.uuid
139
- end
140
- end
113
+ end
141
114
 
142
- end
115
+ includer.define_singleton_method :default_scope do
116
+ includer.all.order("#{includer.table_name}.ordinal ASC") if includer.columns_hash['ordinal'].present?
117
+ includer.all.order("#{includer.table_name}.created_at ASC")
118
+ #relation = base.all
119
+ #scopes.each do |s| relation = relation.send s.to_sym end
120
+ #relation
121
+ end
143
122
 
144
- module ClassMethods
123
+ def soft_destroy
124
+ self.closed_at = Time.now
125
+ self.defunct = true
126
+ self.save
127
+ end
145
128
 
146
- def to_id(model)
147
- model.respond_to?(:id) ? model.id : model
148
- end
129
+ def build_slug
130
+ if respond_to? :name
131
+ name
132
+ elsif respond_to? :title
133
+ title
134
+ else
135
+ ::SecureRandom.uuid
136
+ end
137
+ end
149
138
 
150
- def notation_column(*names)
151
- names.each do |name|
152
- name = name.to_s
153
- instance_eval do
154
- define_method(name) do
155
- notation.try(:[], 'columns').try(:[], name)
156
- end
157
- define_method("#{name}=") do |value|
158
- notation['columns'] ||= {}
159
- notation['columns'][name] = value
160
- end
161
- end
162
- end
163
- end
139
+ end
164
140
 
165
- def notation_boolean_column(*names)
166
- names.each do |name|
167
- name = name.to_s
168
- instance_eval do
169
- define_method("#{name}?") do
170
- notation.try(:[], 'columns').try(:[], name)
171
- end
172
- define_method("#{name}=") do |value|
173
- notation['columns'] ||= {}
174
- notation['columns'][name] = value
175
- end
176
- end
177
- end
178
- end
141
+ module ClassMethods
179
142
 
180
- end
143
+ def to_id(model)
144
+ model.respond_to?(:id) ? model.id : model
145
+ end
181
146
 
147
+ def notation_column(*names)
148
+ names.each do |name|
149
+ name = name.to_s
150
+ instance_eval do
151
+ define_method(name) do
152
+ notation.try(:[], 'columns').try(:[], name)
153
+ end
154
+ define_method("#{name}=") do |value|
155
+ notation['columns'] ||= {}
156
+ notation['columns'][name] = value
157
+ end
158
+ end
182
159
  end
160
+ end
183
161
 
162
+ def notation_boolean_column(*names)
163
+ names.each do |name|
164
+ name = name.to_s
165
+ instance_eval do
166
+ define_method("#{name}?") do
167
+ notation.try(:[], 'columns').try(:[], name)
168
+ end
169
+ define_method("#{name}=") do |value|
170
+ notation['columns'] ||= {}
171
+ notation['columns'][name] = value
172
+ end
173
+ end
174
+ end
184
175
  end
176
+
185
177
  end
186
- end
178
+
179
+ end
@@ -0,0 +1,29 @@
1
+ module Unidom::Common::Concerns::Sha1Digester
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ included do |includer|
6
+
7
+ def digest(message, pepper: nil)
8
+ self.class.digest message, pepper: pepper
9
+ end
10
+
11
+ def hex_digest(message, pepper: nil)
12
+ self.class.hex_digest message, pepper: pepper
13
+ end
14
+
15
+ end
16
+
17
+ module ClassMethods
18
+
19
+ def digest(message, pepper: nil)
20
+ message.present? ? Digest::SHA1.digest("#{message}_#{Rails.application.secrets[:secret_key_base]}_#{pepper}") : nil
21
+ end
22
+
23
+ def hex_digest(message, pepper: nil)
24
+ message.present? ? Unidom::Common::Numeration.hex(digest(message, pepper: pepper)) : nil
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,29 @@
1
+ module Unidom::Common::Concerns::Sha2Digester
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ included do |includer|
6
+
7
+ def digest(message, pepper: nil)
8
+ self.class.digest message, pepper: pepper
9
+ end
10
+
11
+ def hex_digest(message, pepper: nil)
12
+ self.class.hex_digest message, pepper: pepper
13
+ end
14
+
15
+ end
16
+
17
+ module ClassMethods
18
+
19
+ def digest(message, pepper: nil)
20
+ message.present? ? Digest::SHA2.digest("#{message}_#{Rails.application.secrets[:secret_key_base]}_#{pepper}") : nil
21
+ end
22
+
23
+ def hex_digest(message, pepper: nil)
24
+ message.present? ? Unidom::Common::Numeration.hex(digest(message, pepper: pepper)) : nil
25
+ end
26
+
27
+ end
28
+
29
+ end
data/lib/unidom/common.rb CHANGED
@@ -5,8 +5,8 @@ require 'unidom/common/numeration'
5
5
  module Unidom
6
6
  module Common
7
7
 
8
- NULL_UUID = '00000000-0000-0000-0000-000000000000' #.freeze
9
- SELF = '~' #.freeze
8
+ NULL_UUID = '00000000-0000-0000-0000-000000000000'.freeze
9
+ SELF = '~'.freeze
10
10
 
11
11
  #OPENED_AT = Time.utc(1970).freeze
12
12
  #CLOSED_AT = Time.utc(3000).freeze
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Common
3
- VERSION = '1.2'.freeze
3
+ VERSION = '1.3'.freeze
4
4
  end
5
5
  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.2'
4
+ version: '1.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-09 00:00:00.000000000 Z
11
+ date: 2016-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -84,7 +84,9 @@ files:
84
84
  - app/models/unidom/common/concerns/aes256_cryptor.rb
85
85
  - app/models/unidom/common/concerns/md5_digester.rb
86
86
  - app/models/unidom/common/concerns/model_extension.rb
87
+ - app/models/unidom/common/concerns/sha1_digester.rb
87
88
  - app/models/unidom/common/concerns/sha256_digester.rb
89
+ - app/models/unidom/common/concerns/sha2_digester.rb
88
90
  - app/models/unidom/common/concerns/sha384_digester.rb
89
91
  - app/models/unidom/common/concerns/sha512_digester.rb
90
92
  - app/views/layouts/unidom/common/application.html.erb