polish_validators_rails 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 74e328f21ccf92fefc290aa51f847572581e3f68
4
+ data.tar.gz: 2da252fe62c1773d4b3a182d77232398515dcf08
5
+ SHA512:
6
+ metadata.gz: 1baab7bc7c96ff9222ad0dca5eae084a1ce282feab49e1c7ab659e5e631fc8c7db0ace85ff8387ae06d551954cee2957228f6db409c51f52d779f10bb5136c6b
7
+ data.tar.gz: 59de90542ba57ea4df39d9df7a95f8b87fbec4ef7944606d719ecf7ec56b7affe9231b5974285bc19867b912bbec1cf380d8f128c34000c272f3c6008068a247
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in polish_validators_rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Damian Baćkowski
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # PolishValidatorsRails [![Build Status](https://travis-ci.org/dbackowski/polish_validators_rails.svg?branch=master)](https://travis-ci.org/dbackowski/polish_validators_rails)
2
+
3
+ Rails validators for polish numbers: PESEL, NIP, REGON
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'polish_validators_rails'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install polish_validators_rails
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ class User
25
+ include ActiveModel::Validations
26
+
27
+ attr_accessor :nip, :pesel, :regon
28
+
29
+ validates :nip, nip: true
30
+ validates :pesel, pesel: true
31
+ validates :regon, regon: true
32
+ end
33
+
34
+ user = User.new
35
+ user.nip = 1234563218
36
+ user.pesel = 44051401359
37
+ user.regon = 12345678512347
38
+ user.valid?
39
+ => true
40
+ ```
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,3 @@
1
+ module PolishValidatorsRails
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,24 @@
1
+ require 'polish_validators_rails/version'
2
+ require 'polish_validators'
3
+ require 'active_record'
4
+
5
+ class NipValidator < ActiveModel::EachValidator
6
+ def validate_each(record, attribute, value)
7
+ validator = ::PolishValidators::NipValidator.new(value)
8
+ record.errors.add(attribute, @options[:message] || 'Invalid NIP format') unless validator.valid?
9
+ end
10
+ end
11
+
12
+ class PeselValidator < ActiveModel::EachValidator
13
+ def validate_each(record, attribute, value)
14
+ validator = ::PolishValidators::PeselValidator.new(value)
15
+ record.errors.add(attribute, @options[:message] || 'Invalid PESEL format') unless validator.valid?
16
+ end
17
+ end
18
+
19
+ class RegonValidator < ActiveModel::EachValidator
20
+ def validate_each(record, attribute, value)
21
+ validator = ::PolishValidators::RegonValidator.new(value)
22
+ record.errors.add(attribute, @options[:message] || 'Invalid REGON format') unless validator.valid?
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'polish_validators_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "polish_validators_rails"
8
+ spec.version = PolishValidatorsRails::VERSION
9
+ spec.authors = ["Damian Baćkowski"]
10
+ spec.email = ["dbackowski@artcom.pl"]
11
+ spec.summary = %q{Rails validators for polish numbers: PESEL, NIP, REGON}
12
+ spec.description = %q{Rails validators for polish numbers: PESEL, NIP, REGON}
13
+ spec.homepage = "https://github.com/dbackowski/polish_validators_rails"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'polish_validators', '= 1.0.0', '= 1.0.0'
22
+ spec.add_runtime_dependency 'activerecord', '>= 4.0.1', '< 5.0'
23
+ spec.add_development_dependency "rspec", "~> 3.1"
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'PolishValidatorRails' do
4
+ before(:all) do
5
+ class Dummy
6
+ include ActiveModel::Validations
7
+
8
+ attr_accessor :nip, :pesel, :regon
9
+
10
+ validates :nip, nip: true
11
+ validates :pesel, pesel: true
12
+ validates :regon, regon: true
13
+ end
14
+ end
15
+
16
+ describe 'any class that include ActiveModel::Validations' do
17
+ it "has :nip validator" do
18
+ expect(Dummy.validators.map(&:class).include?(NipValidator)).to be_truthy
19
+ end
20
+
21
+ it "has :pesel validator" do
22
+ expect(Dummy.validators.map(&:class).include?(PeselValidator)).to be_truthy
23
+ end
24
+
25
+ it "has :regon validator" do
26
+ expect(Dummy.validators.map(&:class).include?(RegonValidator)).to be_truthy
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,2 @@
1
+ require 'polish_validators_rails'
2
+ require 'active_model'
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: polish_validators_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Damian Baćkowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: polish_validators
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.1
34
+ - - <
35
+ - !ruby/object:Gem::Version
36
+ version: '5.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 4.0.1
44
+ - - <
45
+ - !ruby/object:Gem::Version
46
+ version: '5.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.1'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '3.1'
61
+ - !ruby/object:Gem::Dependency
62
+ name: bundler
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '1.7'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: '1.7'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ version: '10.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ version: '10.0'
89
+ description: 'Rails validators for polish numbers: PESEL, NIP, REGON'
90
+ email:
91
+ - dbackowski@artcom.pl
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - .gitignore
97
+ - .rspec
98
+ - .travis.yml
99
+ - Gemfile
100
+ - LICENSE.txt
101
+ - README.md
102
+ - Rakefile
103
+ - lib/polish_validators_rails.rb
104
+ - lib/polish_validators_rails/version.rb
105
+ - polish_validators_rails.gemspec
106
+ - spec/polish_validators_rails_spec.rb
107
+ - spec/spec_helper.rb
108
+ homepage: https://github.com/dbackowski/polish_validators_rails
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.0.14
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: 'Rails validators for polish numbers: PESEL, NIP, REGON'
132
+ test_files:
133
+ - spec/polish_validators_rails_spec.rb
134
+ - spec/spec_helper.rb