unidom-certificate-china 1.1.1 → 1.2
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 +4 -4
- data/README.md +28 -2
- data/Rakefile +2 -2
- data/app/assets/config/unidom-certificate-china_manifest.js +2 -0
- data/app/assets/javascripts/unidom/certificate/china/application.js +1 -1
- data/app/assets/stylesheets/unidom/certificate/china/application.css +3 -3
- data/app/controllers/unidom/certificate/china/application_controller.rb +3 -1
- data/app/jobs/unidom/certificate/china/application_job.rb +2 -0
- data/app/mailers/unidom/certificate/china/application_mailer.rb +4 -0
- data/app/models/unidom/certificate/china/application_record.rb +3 -0
- data/app/models/unidom/certificate/china/business_license.rb +1 -1
- data/app/models/unidom/certificate/china/concerns/as_business_license_certificated.rb +1 -1
- data/app/models/unidom/certificate/china/concerns/as_identity_card_certificated.rb +1 -1
- data/app/models/unidom/certificate/china/identity_card.rb +7 -5
- data/app/validators/unidom/certificate/china/identification_number_validator.rb +16 -0
- data/lib/unidom/certificate/china/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d68210d407c3089f6202c860ad025d92f32774c2
|
4
|
+
data.tar.gz: bedbe5bf19ce29d1e3ad71d7d0d4ed4ce647bc63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b542bd93325c5e00c606917c9d731eafeba22e3356eed1c6e0823d779bc4783d81ea3441c48049bf1678b2bb833032de7259328ec114be8afffaeaf0ad86b2e
|
7
|
+
data.tar.gz: 50407607004cc9d2e78727ecd1cbc5961dafec4e00c0dbe84db7613600953228ccc476465608078aa1dca48e39639a1f81c3c5feb274bee1006e85779c21908c
|
data/README.md
CHANGED
@@ -2,26 +2,39 @@
|
|
2
2
|
|
3
3
|
[](http://opensource.org/licenses/MIT)
|
4
4
|
[](https://badge.fury.io/rb/unidom-certificate-china)
|
5
|
+
[](https://gemnasium.com/github.com/topbitdu/unidom-certificate-china)
|
5
6
|
|
6
7
|
Unidom (UNIfied Domain Object Model) is a series of domain model engines. The China Certificate domain model engine includes Identity Card, Driving License, and Business License models.
|
7
8
|
Unidom (统一领域对象模型)是一系列的领域模型引擎。中国证件领域模型引擎包括中国大陆的身份证、驾驶证、营业执照等模型。
|
8
9
|
|
10
|
+
|
11
|
+
|
9
12
|
## Recent Update
|
13
|
+
|
10
14
|
Check out the [Road Map](ROADMAP.md) to find out what's the next.
|
11
15
|
Check out the [Change Log](CHANGELOG.md) to find out what's new.
|
12
16
|
|
17
|
+
|
18
|
+
|
13
19
|
## Usage in Gemfile
|
20
|
+
|
14
21
|
```ruby
|
15
22
|
gem 'unidom-certificate-china'
|
16
23
|
```
|
17
24
|
|
25
|
+
|
26
|
+
|
18
27
|
## Run the Database Migration
|
28
|
+
|
19
29
|
```shell
|
20
30
|
rake db:migrate
|
21
31
|
```
|
22
32
|
The migration versions start with 2001029156.
|
23
33
|
|
34
|
+
|
35
|
+
|
24
36
|
## Call the Model
|
37
|
+
|
25
38
|
```ruby
|
26
39
|
identity_card = Unidom::Certificate::China::IdentityCard.identification_number_is('51010519801231123X').first_or_create(
|
27
40
|
name: 'John',
|
@@ -44,18 +57,31 @@ Unidom::Certificate::China::BusinessLicense.registration_number_is('510105012345
|
|
44
57
|
)
|
45
58
|
```
|
46
59
|
|
60
|
+
|
61
|
+
|
47
62
|
## Include the Concerns
|
63
|
+
|
48
64
|
```ruby
|
49
65
|
include Unidom::Certificate::China::Concerns::AsBusinessLicenseCertificated
|
50
66
|
include Unidom::Certificate::China::Concerns::AsIdentityCardCertificated
|
51
67
|
```
|
52
68
|
|
53
69
|
### As Business License Certificated
|
70
|
+
|
54
71
|
The As Business License Certificated do the following tasks for the includer automatically:
|
55
|
-
1. Include the [As Certificated](http://https://github.com/topbitdu/unidom-certificated) concern
|
72
|
+
1. Include the [As Certificated](http://https://github.com/topbitdu/unidom-certificated) concern
|
56
73
|
2. Define the has_many :china_business_licenses macro as: ``has_many :china_business_licenses, through: :certificatings, source: :certification, source_type: 'Unidom::Certificate::China::BusinessLicense'``
|
57
74
|
|
58
75
|
### As Identity Card Certificated
|
76
|
+
|
59
77
|
The As Identity Card Certificated do the following tasks for the includer automatically:
|
60
|
-
1. Include the [As Certificated](http://https://github.com/topbitdu/unidom-certificated) concern
|
78
|
+
1. Include the [As Certificated](http://https://github.com/topbitdu/unidom-certificated) concern
|
61
79
|
2. Define the has_many :china_identity_cards macro as: ``has_many :china_identity_cards, through: :certificatings, source: :certification, source_type: 'Unidom::Certificate::China::IdentityCard'``
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
## Validator
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
validates :identification_number, presence: true, identification_number: true
|
87
|
+
```
|
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
10
|
rdoc.rdoc_dir = 'rdoc'
|
11
11
|
rdoc.title = 'Unidom Certificate China'
|
12
12
|
rdoc.options << '--line-numbers'
|
13
|
-
rdoc.rdoc_files.include('README.
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
14
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
15
|
end
|
16
16
|
|
@@ -20,5 +20,5 @@ load 'rails/tasks/statistics.rake'
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
-
|
23
|
+
require 'bundler/gem_tasks'
|
24
24
|
|
@@ -5,7 +5,7 @@
|
|
5
5
|
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
6
|
//
|
7
7
|
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// compiled file.
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
9
|
//
|
10
10
|
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
11
|
// about supported directives.
|
@@ -6,9 +6,9 @@
|
|
6
6
|
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
7
|
*
|
8
8
|
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any
|
10
|
-
*
|
11
|
-
* file per style scope.
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
12
|
*
|
13
13
|
*= require_self
|
14
14
|
*/
|
@@ -4,7 +4,7 @@ module Unidom::Certificate::China::Concerns::AsBusinessLicenseCertificated
|
|
4
4
|
|
5
5
|
include Unidom::Certificate::Concerns::AsCertificated
|
6
6
|
|
7
|
-
|
7
|
+
included do |includer|
|
8
8
|
|
9
9
|
has_many :china_business_licenses, through: :certificatings, source: :certification, source_type: 'Unidom::Certificate::China::BusinessLicense'
|
10
10
|
|
@@ -4,7 +4,7 @@ module Unidom::Certificate::China::Concerns::AsIdentityCardCertificated
|
|
4
4
|
|
5
5
|
include Unidom::Certificate::Concerns::AsCertificated
|
6
6
|
|
7
|
-
|
7
|
+
included do |includer|
|
8
8
|
|
9
9
|
has_many :china_identity_cards, through: :certificatings, source: :certification, source_type: 'Unidom::Certificate::China::IdentityCard'
|
10
10
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Identity Card 是中国身份证。
|
2
2
|
|
3
|
-
class Unidom::Certificate::China::IdentityCard <
|
3
|
+
class Unidom::Certificate::China::IdentityCard < Unidom::Certificate::China::ApplicationRecord
|
4
4
|
|
5
5
|
FORMAT_VALIDATION_REGEX = /\A\d{17}[\dx]\z/i
|
6
6
|
|
@@ -18,10 +18,12 @@ class Unidom::Certificate::China::IdentityCard < ActiveRecord::Base
|
|
18
18
|
|
19
19
|
scope :identification_number_is, ->(identification_number) { where identification_number: identification_number }
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
after_validation do
|
22
|
+
if errors.blank?
|
23
|
+
self.identification_number = self.identification_number.upcase
|
24
|
+
self.birth_date = Date.parse "#{identification_number[6..9]}-#{identification_number[10..11]}-#{identification_number[12..13]}"
|
25
|
+
self.gender_code = identification_number[16].to_i.odd? ? '1' : '2'
|
26
|
+
end
|
25
27
|
end
|
26
28
|
|
27
29
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Unidom::Certificate::China::IdentificationNumberValidator < ActiveModel::EachValidator
|
2
|
+
|
3
|
+
WEIGHTS = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ].freeze
|
4
|
+
CHECK_DIGITS = %w{1 0 X 9 8 7 6 5 4 3 2}.freeze
|
5
|
+
|
6
|
+
def validate_each(record, attribute, value)
|
7
|
+
|
8
|
+
value = value.to_s
|
9
|
+
sum = 0
|
10
|
+
value[0..16].chars.each_with_index do |char, index| sum += char.to_i*WEIGHTS[index] end
|
11
|
+
|
12
|
+
record.errors[attribute] << (options[:message]||'is invalid') unless CHECK_DIGITS[sum%11]==value[17]
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unidom-certificate-china
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: '1.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: 2016-
|
11
|
+
date: 2016-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-common
|
@@ -50,14 +50,19 @@ files:
|
|
50
50
|
- MIT-LICENSE
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
|
+
- app/assets/config/unidom-certificate-china_manifest.js
|
53
54
|
- app/assets/javascripts/unidom/certificate/china/application.js
|
54
55
|
- app/assets/stylesheets/unidom/certificate/china/application.css
|
55
56
|
- app/controllers/unidom/certificate/china/application_controller.rb
|
56
57
|
- app/helpers/unidom/certificate/china/application_helper.rb
|
58
|
+
- app/jobs/unidom/certificate/china/application_job.rb
|
59
|
+
- app/mailers/unidom/certificate/china/application_mailer.rb
|
60
|
+
- app/models/unidom/certificate/china/application_record.rb
|
57
61
|
- app/models/unidom/certificate/china/business_license.rb
|
58
62
|
- app/models/unidom/certificate/china/concerns/as_business_license_certificated.rb
|
59
63
|
- app/models/unidom/certificate/china/concerns/as_identity_card_certificated.rb
|
60
64
|
- app/models/unidom/certificate/china/identity_card.rb
|
65
|
+
- app/validators/unidom/certificate/china/identification_number_validator.rb
|
61
66
|
- app/views/layouts/unidom/certificate/china/application.html.erb
|
62
67
|
- config/routes.rb
|
63
68
|
- db/migrate/20010291560010_create_unidom_china_identity_cards.rb
|