validates_identity 0.1.0 → 0.2.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: a9b5937129800250884456627b93b6a8966523f1500109fccaf9c325f75be4ba
4
+ data.tar.gz: 0e411812a260b49a7f541e6ddbedcc3cb58e296d1bc3231f3097505505a92b75
5
5
  SHA512:
6
- metadata.gz: 44499e3ed8a5279780b2f8e331af8e33cf9d14aa6d1ab6c6c3ea6809e1c23c7904cd2e9db0f4acbfdc452ab851ce93f10e2afb9ea6e9c430d517f0e19895bdb4
7
- data.tar.gz: 0e853984a43b4e75b607fd8582187685bd472acdf76262cc5b3dbe220f29d5c6d487d8f620c17e1ae1a9d6b5e34104f7314254c79081464166d220a7c806f432
6
+ metadata.gz: 035474f190f44cb5a087dc36bace8ac6d7d794a2f75038fe5ede863d009981df90c9ba0190b72d159f046a4ec06728cba7b0776b68506b644dc742516008a136
7
+ data.tar.gz: 8839f1aba9aac3383a5b1323504c415d36ec626ec9f5cc4b3e60846160b47e116012295f6f0d0e93152ebaa750f590eb76526ae110cccb5ff0b4aaf81a17fd82
data/.rubocop.yml CHANGED
@@ -1,13 +1,16 @@
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
7
11
 
8
- Style/StringLiteralsInInterpolation:
9
- Enabled: true
10
- EnforcedStyle: double_quotes
12
+ Metrics/BlockLength:
13
+ Enabled: false
11
14
 
12
- Layout/LineLength:
13
- Max: 120
15
+ Style/Documentation:
16
+ 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,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2024-02-25
4
+
5
+ ### Added
6
+
7
+ - Initial Implementation of public API's
8
+
3
9
  ## [0.1.0] - 2024-02-24
4
10
 
11
+ ### Added
12
+
5
13
  - 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.1.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,33 @@ 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
+ New Identity Validators can be registered through the public apis of `ValidatesIdentity`
35
+
36
+ ```ruby
37
+ ValidatesIdentity.register_identity_type('CustomIdentity', CustomIdentityValidator)
38
+ ```
39
+
40
+ Each Validator should have:
41
+
42
+ - a constructor with 2 params: `value` and `options` as a hash
43
+ - a `valid?` method that returns a boolean
44
+
45
+ In case of a legacy system where keys were already defined and differ from the official ones, aliases can be registered as well
46
+
47
+ ```ruby
48
+ ValidatesIdentity.register_identity_type_alias('LegacyIdentity', 'CustomIdentity')
49
+ ```
26
50
 
27
51
  ## Development
28
52
 
@@ -32,7 +56,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
56
 
33
57
  ## Contributing
34
58
 
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).
59
+ 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
60
 
37
61
  ## License
38
62
 
@@ -40,4 +64,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
40
64
 
41
65
  ## Code of Conduct
42
66
 
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).
67
+ 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,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ class IdentityValidator < ActiveModel::EachValidator
4
+ def validate_each(record, attribute, value)
5
+ identity = ValidatesIdentity::Identity.new(record, value, options)
6
+
7
+ return if identity.valid?
8
+
9
+ ruby_prior_version_three =
10
+ Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.0.0')
11
+
12
+ if ruby_prior_version_three
13
+ record.errors.add(attribute, :invalid, options)
14
+ else
15
+ record.errors.add(attribute, :invalid, **options)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ValidatesIdentity
4
+ class Identity
5
+ attr_reader :record, :value, :options
6
+
7
+ def initialize(record, value, options)
8
+ @record = record
9
+ @value = value
10
+ @options = options
11
+ end
12
+
13
+ def valid?
14
+ return true if value.blank?
15
+ return false if options[:identity_type].blank?
16
+
17
+ validator_class = ValidatesIdentity.get_validator(identity_type)
18
+
19
+ return false if validator_class.nil?
20
+
21
+ validator = validator_class.new(value, options)
22
+ validator.valid?
23
+ end
24
+
25
+ private
26
+
27
+ def identity_type
28
+ record.send(options[:identity_type])
29
+ rescue NoMethodError
30
+ :invalid
31
+ end
32
+ end
33
+ 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.2.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.2.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