brid-rails 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in brid-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Halan Pinheiro
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,25 @@
1
+ # Brid-rails
2
+
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ gem 'brid-rails'
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install brid-rails
17
+
18
+
19
+ ## Contributing
20
+
21
+ 1. Fork it
22
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
23
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
24
+ 4. Push to the branch (`git push origin my-new-feature`)
25
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/brid-rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Halan Pinheiro"]
6
+ gem.email = ["halan.pinheiro@gmail.com"]
7
+ gem.description = %q{Implementation of Brid gem on ActiveModel}
8
+ gem.summary = %q{Implementation of Brid gem on ActiveModel}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "brid-rails"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Brid::Rails::VERSION
17
+
18
+ gem.add_runtime_dependency 'activemodel', ['~> 3.0']
19
+ gem.add_runtime_dependency 'brid', ['~> 0.2']
20
+ end
@@ -0,0 +1,13 @@
1
+ module ActiveModel
2
+ module Validations
3
+ class CnpjValidator < ActiveModel::EachValidator
4
+ def validate_each(record, attr_name, value)
5
+ return if options[:allow_nil] && value.nil?
6
+
7
+ unless(CNPJ.new(value).valid?() rescue false)
8
+ record.errors.add(attr_name, (options[:message] || :cnpj_not_valid))
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module ActiveModel
2
+ module Validations
3
+ class CpfOrCnpjValidator < ActiveModel::EachValidator
4
+ def validate_each(record, attr_name, value)
5
+ return if options[:allow_nil] && value.nil?
6
+
7
+ unless Brid.detect value, [:cpf, :cnpj]
8
+ record.errors.add(attr_name, (options[:message] || :cpf_not_valid))
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module ActiveModel
2
+ module Validations
3
+ class CpfValidator < ActiveModel::EachValidator
4
+ def validate_each(record, attr_name, value)
5
+ return if options[:allow_nil] && value.nil?
6
+
7
+
8
+ unless(CPF.new(value).valid?() rescue false)
9
+ record.errors.add(attr_name, (options[:message] || :cpf_not_valid))
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ module ActiveModel
2
+ module Validations
3
+ class LuhnValidator < ActiveModel::EachValidator
4
+ def valid_number? number, luhn_method = :mod10
5
+ digits = options[:with]
6
+ number != number[0, number.length - digits].send(luhn_method, digits)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ module ActiveModel
2
+ module Validations
3
+ class Mod10Validator < LuhnValidator
4
+ def validate_each(record, attr_name, value)
5
+ return if options[:allow_nil] && value.nil?
6
+ if valid_number? value, :mod10
7
+ record.errors.add(attr_name, (options[:message] || :mod10_not_valid))
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module ActiveModel
2
+ module Validations
3
+ class Mod11Validator < LuhnValidator
4
+ def validate_each(record, attr_name, value)
5
+ return if options[:allow_nil] && value.nil?
6
+ if valid_number? value, :mod11
7
+ record.errors.add(attr_name, (options[:message] || :mod11_not_valid))
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ module ActiveModel
2
+ module Validations
3
+ class PisValidator < ActiveModel::EachValidator
4
+ def validate_each(record, attr_name, value)
5
+ return if options[:allow_nil] && value.nil?
6
+
7
+ unless(PIS.new(value).valid?() rescue false)
8
+ record.errors.add(attr_name, (options[:message] || :pis_not_valid))
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module ActiveModel
2
+ module Validations
3
+ class TituloEleitorValidator < ActiveModel::EachValidator
4
+ def validate_each(record, attr_name, value)
5
+ return if options[:allow_nil] && value.nil?
6
+
7
+ unless(TituloEleitor.new(value).valid?() rescue false)
8
+ record.errors.add(attr_name, (options[:message] || :titulo_eleitor_not_valid))
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Brid
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/brid-rails.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "brid-rails/version"
2
+ require 'brid'
3
+ require 'active_model/validations'
4
+ require 'active_model/validations/luhn_validator'
5
+ require 'active_model/validations/mod10_validator'
6
+ require 'active_model/validations/mod11_validator'
7
+ require 'active_model/validations/cpf_validator'
8
+ require 'active_model/validations/cnpj_validator'
9
+ require 'active_model/validations/cpf_or_cnpj_validator'
10
+ require 'active_model/validations/pis_validator'
11
+ require 'active_model/validations/titulo_eleitor_validator'
12
+
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brid-rails
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Halan Pinheiro
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-07-24 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activemodel
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 7
29
+ segments:
30
+ - 3
31
+ - 0
32
+ version: "3.0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: brid
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 15
44
+ segments:
45
+ - 0
46
+ - 2
47
+ version: "0.2"
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ description: Implementation of Brid gem on ActiveModel
51
+ email:
52
+ - halan.pinheiro@gmail.com
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ files:
60
+ - .gitignore
61
+ - Gemfile
62
+ - LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - brid-rails.gemspec
66
+ - lib/active_model/validations/cnpj_validator.rb
67
+ - lib/active_model/validations/cpf_or_cnpj_validator.rb
68
+ - lib/active_model/validations/cpf_validator.rb
69
+ - lib/active_model/validations/luhn_validator.rb
70
+ - lib/active_model/validations/mod10_validator.rb
71
+ - lib/active_model/validations/mod11_validator.rb
72
+ - lib/active_model/validations/pis_validator.rb
73
+ - lib/active_model/validations/titulo_eleitor_validator.rb
74
+ - lib/brid-rails.rb
75
+ - lib/brid-rails/version.rb
76
+ homepage: ""
77
+ licenses: []
78
+
79
+ post_install_message:
80
+ rdoc_options: []
81
+
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ requirements: []
103
+
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.24
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: Implementation of Brid gem on ActiveModel
109
+ test_files: []
110
+
111
+ has_rdoc: