validates_identity 0.1.0 → 0.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: c02ac962c5ec8b1375b107a1cd166a4242e6b0dc3d1eac6cd72c677886bc2949
4
- data.tar.gz: 054340d538b549470ba24f72be4927f911ea0965114e6fa7969cceb5a59d0e98
3
+ metadata.gz: 3848016930f18f09b27ec31333622b53df51786d31c3eb612fe92da34c9f640a
4
+ data.tar.gz: c07d435462ce6caa0e3c4d1611af1aa2cfa8f06956a331696773845fafb6a02f
5
5
  SHA512:
6
- metadata.gz: 44499e3ed8a5279780b2f8e331af8e33cf9d14aa6d1ab6c6c3ea6809e1c23c7904cd2e9db0f4acbfdc452ab851ce93f10e2afb9ea6e9c430d517f0e19895bdb4
7
- data.tar.gz: 0e853984a43b4e75b607fd8582187685bd472acdf76262cc5b3dbe220f29d5c6d487d8f620c17e1ae1a9d6b5e34104f7314254c79081464166d220a7c806f432
6
+ metadata.gz: 539ce96f3cc65ca74b12ea9b83a6aaa568e3c15bb178e945c1224893092e6741f5abf6f69db65fe989163c2d528a808f34f3b9704b800b5a550e179f4a50bcea
7
+ data.tar.gz: ab5c1fe930362622f2efd4c928f71246aef44db216f36fd795492b5fbe4a7cdc3b11c27c295c95ba60f853ff46501b4f037dd379b2b1cf5fe681df46bcc1361f
data/.rubocop.yml CHANGED
@@ -1,13 +1,19 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
1
5
  AllCops:
6
+ NewCops: enable
2
7
  TargetRubyVersion: 2.6
3
8
 
4
- Style/StringLiterals:
5
- Enabled: true
6
- EnforcedStyle: double_quotes
9
+ Layout/LineLength:
10
+ Max: 150
11
+
12
+ Metrics/BlockLength:
13
+ Enabled: false
7
14
 
8
- Style/StringLiteralsInInterpolation:
9
- Enabled: true
10
- EnforcedStyle: double_quotes
15
+ Metrics/MethodLength:
16
+ Max: 15
11
17
 
12
- Layout/LineLength:
13
- Max: 120
18
+ Style/Documentation:
19
+ Enabled: false
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ validate_identity
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
- ## [Unreleased]
1
+ ## [0.3.0] - 2024-02-25
2
+
3
+ ### Added
4
+
5
+ - `Format` option to format the final identity value
6
+
7
+ ## [0.2.0] - 2024-02-25
8
+
9
+ ### Added
10
+
11
+ - Initial Implementation of public API's
2
12
 
3
13
  ## [0.1.0] - 2024-02-24
4
14
 
15
+ ### Added
16
+
5
17
  - Initial release
data/Gemfile CHANGED
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in validates_identity.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
9
-
10
- gem "rspec", "~> 3.0"
11
-
12
- gem "rubocop", "~> 1.21"
8
+ gem 'jazz_fingers'
9
+ gem 'rake'
10
+ gem 'rspec'
11
+ gem 'rubocop-rake'
12
+ gem 'rubocop-rspec'
13
+ gem 'shoulda-matchers'
data/Gemfile.lock ADDED
@@ -0,0 +1,124 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ validates_identity (0.3.0)
5
+ activemodel
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (7.1.3.2)
11
+ activesupport (= 7.1.3.2)
12
+ activesupport (7.1.3.2)
13
+ base64
14
+ bigdecimal
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ connection_pool (>= 2.2.5)
17
+ drb
18
+ i18n (>= 1.6, < 2)
19
+ minitest (>= 5.1)
20
+ mutex_m
21
+ tzinfo (~> 2.0)
22
+ amazing_print (1.5.0)
23
+ ast (2.4.2)
24
+ base64 (0.2.0)
25
+ bigdecimal (3.1.6)
26
+ byebug (11.1.3)
27
+ coderay (1.1.3)
28
+ concurrent-ruby (1.2.3)
29
+ connection_pool (2.4.1)
30
+ coolline (0.5.0)
31
+ unicode_utils (~> 1.4)
32
+ diff-lcs (1.5.1)
33
+ drb (2.2.0)
34
+ ruby2_keywords
35
+ i18n (1.14.1)
36
+ concurrent-ruby (~> 1.0)
37
+ jazz_fingers (6.2.0)
38
+ amazing_print (~> 1.3)
39
+ pry (~> 0.10)
40
+ pry-byebug (~> 3.9)
41
+ pry-coolline (~> 0.2)
42
+ json (2.7.1)
43
+ language_server-protocol (3.17.0.3)
44
+ method_source (1.0.0)
45
+ minitest (5.22.2)
46
+ mutex_m (0.2.0)
47
+ parallel (1.24.0)
48
+ parser (3.3.0.5)
49
+ ast (~> 2.4.1)
50
+ racc
51
+ pry (0.14.2)
52
+ coderay (~> 1.1)
53
+ method_source (~> 1.0)
54
+ pry-byebug (3.10.1)
55
+ byebug (~> 11.0)
56
+ pry (>= 0.13, < 0.15)
57
+ pry-coolline (0.2.6)
58
+ coolline (~> 0.5)
59
+ pry (~> 0.13)
60
+ racc (1.7.3)
61
+ rainbow (3.1.1)
62
+ rake (13.1.0)
63
+ regexp_parser (2.9.0)
64
+ rexml (3.2.6)
65
+ rspec (3.13.0)
66
+ rspec-core (~> 3.13.0)
67
+ rspec-expectations (~> 3.13.0)
68
+ rspec-mocks (~> 3.13.0)
69
+ rspec-core (3.13.0)
70
+ rspec-support (~> 3.13.0)
71
+ rspec-expectations (3.13.0)
72
+ diff-lcs (>= 1.2.0, < 2.0)
73
+ rspec-support (~> 3.13.0)
74
+ rspec-mocks (3.13.0)
75
+ diff-lcs (>= 1.2.0, < 2.0)
76
+ rspec-support (~> 3.13.0)
77
+ rspec-support (3.13.1)
78
+ rubocop (1.60.2)
79
+ json (~> 2.3)
80
+ language_server-protocol (>= 3.17.0)
81
+ parallel (~> 1.10)
82
+ parser (>= 3.3.0.2)
83
+ rainbow (>= 2.2.2, < 4.0)
84
+ regexp_parser (>= 1.8, < 3.0)
85
+ rexml (>= 3.2.5, < 4.0)
86
+ rubocop-ast (>= 1.30.0, < 2.0)
87
+ ruby-progressbar (~> 1.7)
88
+ unicode-display_width (>= 2.4.0, < 3.0)
89
+ rubocop-ast (1.30.0)
90
+ parser (>= 3.2.1.0)
91
+ rubocop-capybara (2.20.0)
92
+ rubocop (~> 1.41)
93
+ rubocop-factory_bot (2.25.1)
94
+ rubocop (~> 1.41)
95
+ rubocop-rake (0.6.0)
96
+ rubocop (~> 1.0)
97
+ rubocop-rspec (2.26.1)
98
+ rubocop (~> 1.40)
99
+ rubocop-capybara (~> 2.17)
100
+ rubocop-factory_bot (~> 2.22)
101
+ ruby-progressbar (1.13.0)
102
+ ruby2_keywords (0.0.5)
103
+ shoulda-matchers (6.1.0)
104
+ activesupport (>= 5.2.0)
105
+ tzinfo (2.0.6)
106
+ concurrent-ruby (~> 1.0)
107
+ unicode-display_width (2.5.0)
108
+ unicode_utils (1.4.0)
109
+
110
+ PLATFORMS
111
+ ruby
112
+ x86_64-darwin-21
113
+
114
+ DEPENDENCIES
115
+ jazz_fingers
116
+ rake
117
+ rspec
118
+ rubocop-rake
119
+ rubocop-rspec
120
+ shoulda-matchers
121
+ validates_identity!
122
+
123
+ BUNDLED WITH
124
+ 2.5.3
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # ValidatesIdentity
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/validates_identity`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ This projects aims to validate several countries person identification documents.
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,49 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ Just use as any other validator:
24
+
25
+ ```ruby
26
+ class User < ActiveRecord::Base
27
+ # :identity_type is the attribute that will be used to determine the identity type and is required
28
+ validates :identity, identity: { identity_type: :identity_type }
29
+ end
30
+ ```
31
+
32
+ ## Advanced Usage
33
+
34
+ ### Format
35
+
36
+ The `format` option can be used to format the final identity value.
37
+
38
+ ```ruby
39
+ class User < ActiveRecord::Base
40
+ # :identity_type is the attribute that will be used to determine the identity type and is required
41
+ validates :identity, identity: { identity_type: :identity_type, format: true }
42
+ end
43
+ ```
44
+
45
+ ### Custom Validators
46
+
47
+ New Identity Validators can be registered through the public apis of `ValidatesIdentity`
48
+
49
+ ```ruby
50
+ ValidatesIdentity.register_identity_type('CustomIdentity', CustomIdentityValidator)
51
+ ```
52
+
53
+ Each Validator should have:
54
+
55
+ - a constructor with 1 param: `value`
56
+ - a `valid?` method that returns a boolean
57
+ - a `formatted` method that returns the value formatted
58
+
59
+ ### Validators Aliases
60
+
61
+ In case of a legacy system where keys were already defined and differ from the official ones, aliases can be registered as well
62
+
63
+ ```ruby
64
+ ValidatesIdentity.register_identity_type_alias('LegacyIdentity', 'CustomIdentity')
65
+ ```
26
66
 
27
67
  ## Development
28
68
 
@@ -32,7 +72,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
72
 
33
73
  ## Contributing
34
74
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/validates_identity. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/validates_identity/blob/master/CODE_OF_CONDUCT.md).
75
+ Bug reports and pull requests are welcome on GitHub at https://github.com/plribeiro3000/validates_identity. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/plribeiro3000/validates_identity/blob/master/CODE_OF_CONDUCT.md).
36
76
 
37
77
  ## License
38
78
 
@@ -40,4 +80,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
40
80
 
41
81
  ## Code of Conduct
42
82
 
43
- Everyone interacting in the ValidatesIdentity project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/validates_identity/blob/master/CODE_OF_CONDUCT.md).
83
+ Everyone interacting in the ValidatesIdentity project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/plribeiro3000/validates_identity/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- require "rubocop/rake_task"
8
+ require 'rubocop/rake_task'
9
9
 
10
10
  RuboCop::RakeTask.new
11
11
 
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ class IdentityValidator < ActiveModel::EachValidator
4
+ def validate_each(record, attribute, value)
5
+ identity = ValidatesIdentity::Identity.new(record, attribute, value, options)
6
+
7
+ if identity.valid?
8
+ record.send("#{attribute}=", identity.formatted) if options[:format]
9
+ else
10
+ ruby_prior_version_three =
11
+ Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.0.0')
12
+
13
+ if ruby_prior_version_three
14
+ record.errors.add(attribute, :invalid, options)
15
+ else
16
+ record.errors.add(attribute, :invalid, **options)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ValidatesIdentity
4
+ class Identity
5
+ attr_reader :record, :attribute, :value, :options
6
+
7
+ def initialize(record, attribute, value, options)
8
+ @record = record
9
+ @attribute = attribute
10
+ @value = value
11
+ @options = options
12
+ end
13
+
14
+ def valid?
15
+ return true if value.blank?
16
+ return false if options[:identity_type].blank?
17
+
18
+ validator_class = ValidatesIdentity.get_validator(identity_type)
19
+
20
+ return false if validator_class.nil?
21
+
22
+ validator = validator_class.new(value)
23
+ validator.valid?
24
+ end
25
+
26
+ private
27
+
28
+ def identity_type
29
+ record.send(options[:identity_type])
30
+ rescue NoMethodError
31
+ :invalid
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ValidatesIdentity
4
- VERSION = "0.1.0"
4
+ VERSION = '0.3.0'
5
5
  end
@@ -1,8 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "validates_identity/version"
3
+ require 'active_model'
4
+ require 'identity_validator'
4
5
 
5
6
  module ValidatesIdentity
6
- class Error < StandardError; end
7
- # Your code goes here...
7
+ autoload :Identity, 'validates_identity/identity'
8
+
9
+ class << self
10
+ private
11
+
12
+ def identity_types
13
+ @identity_types ||= {}
14
+ end
15
+
16
+ def identity_type_aliases
17
+ @identity_type_aliases ||= {}
18
+ end
19
+ end
20
+
21
+ def self.register_identity_type(identity_type_acronym, identity_type_validator)
22
+ identity_types[identity_type_acronym] = identity_type_validator
23
+ identity_type_aliases[identity_type_acronym] = identity_type_acronym
24
+ end
25
+
26
+ def self.register_identity_type_alias(identity_type, identity_type_alias)
27
+ identity_type_aliases[identity_type_alias] = identity_type
28
+ end
29
+
30
+ def self.get_validator(identity_type)
31
+ identity_alias = identity_type_aliases[identity_type]
32
+ identity_types[identity_alias]
33
+ end
8
34
  end
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/validates_identity/version"
3
+ require_relative 'lib/validates_identity/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "validates_identity"
6
+ spec.name = 'validates_identity'
7
7
  spec.version = ValidatesIdentity::VERSION
8
- spec.authors = ["Paulo Ribeiro"]
9
- spec.email = ["plribeiro3000@gmail.com"]
8
+ spec.authors = ['Paulo Ribeiro']
9
+ spec.email = ['plribeiro3000@gmail.com']
10
10
 
11
- spec.summary = "Validates Several Identity Documents and test it with matchers in a simple way."
12
- spec.homepage = "https://github.com/plribeiro3000/validates_identity"
13
- spec.license = "MIT"
14
- spec.required_ruby_version = ">= 2.6.0"
11
+ spec.summary = 'Validates Several Identity Documents and test it with matchers in a simple way.'
12
+ spec.homepage = 'https://github.com/plribeiro3000/validates_identity'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = '>= 2.6.0'
15
15
 
16
- spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
17
  spec.metadata['source_code_uri'] = 'https://github.com/plribeiro3000/validates_identity/blob/master'
18
18
  spec.metadata['changelog_uri'] = 'https://github.com/plribeiro3000/validates_identity/blob/master/CHANGELOG.md'
19
19
 
@@ -24,13 +24,10 @@ Gem::Specification.new do |spec|
24
24
  (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
25
25
  end
26
26
  end
27
- spec.bindir = "exe"
27
+ spec.bindir = 'exe'
28
28
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
- spec.require_paths = ["lib"]
29
+ spec.require_paths = ['lib']
30
30
 
31
- # Uncomment to register a new dependency of your gem
32
- # spec.add_dependency "example-gem", "~> 1.0"
33
-
34
- # For more information and examples about making a new gem, check out our
35
- # guide at: https://bundler.io/guides/creating_gem.html
31
+ spec.add_runtime_dependency 'activemodel'
32
+ spec.metadata['rubygems_mfa_required'] = 'true'
36
33
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_identity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Ribeiro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-24 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-02-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description:
14
28
  email:
15
29
  - plribeiro3000@gmail.com
@@ -19,15 +33,19 @@ extra_rdoc_files: []
19
33
  files:
20
34
  - ".rspec"
21
35
  - ".rubocop.yml"
36
+ - ".ruby-gemset"
37
+ - ".ruby-version"
22
38
  - CHANGELOG.md
23
39
  - CODE_OF_CONDUCT.md
24
40
  - Gemfile
41
+ - Gemfile.lock
25
42
  - LICENSE.txt
26
43
  - README.md
27
44
  - Rakefile
45
+ - lib/identity_validator.rb
28
46
  - lib/validates_identity.rb
47
+ - lib/validates_identity/identity.rb
29
48
  - lib/validates_identity/version.rb
30
- - sig/validates_identity.rbs
31
49
  - validates_identity.gemspec
32
50
  homepage: https://github.com/plribeiro3000/validates_identity
33
51
  licenses:
@@ -36,6 +54,7 @@ metadata:
36
54
  homepage_uri: https://github.com/plribeiro3000/validates_identity
37
55
  source_code_uri: https://github.com/plribeiro3000/validates_identity/blob/master
38
56
  changelog_uri: https://github.com/plribeiro3000/validates_identity/blob/master/CHANGELOG.md
57
+ rubygems_mfa_required: 'true'
39
58
  post_install_message:
40
59
  rdoc_options: []
41
60
  require_paths:
@@ -1,4 +0,0 @@
1
- module ValidatesIdentity
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end