brid-rails 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,42 @@
1
+ module Brid
2
+ module BridActiveRecord
3
+ def self.included base
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ def has_one_cpf field = :cpf
9
+ has_brid field, 'CPF'
10
+ end
11
+
12
+ def has_one_cnpj field = :cnpj
13
+ has_brid field, 'CNPJ'
14
+ end
15
+
16
+ def has_one_pis field = :pis
17
+ has_brid field, 'PIS'
18
+ end
19
+
20
+ def has_one_titulo_eleitor field = :titulo_eleitor
21
+ has_brid field, 'Tituloeleitor'
22
+ end
23
+
24
+ def has_one_cred_card field = :cred_card
25
+ has_brid field, 'CredCard'
26
+ end
27
+
28
+ def has_one_brid field
29
+ has_brid field, 'GenericID'
30
+ end
31
+
32
+
33
+ def has_brid field, klass
34
+ composed_of field,
35
+ :constructor => Proc.new {|number| klass.constantize.new number },
36
+ :converter => Proc.new {|value| klass.constantize.new value },
37
+ :mapping => [field, 'number'],
38
+ :class_name => klass.to_s
39
+ end
40
+ end
41
+ end
42
+ end
data/lib/brid-rails.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "brid-rails/version"
2
2
  require 'brid'
3
3
  require 'active_model/validations'
4
+
4
5
  require 'active_model/validations/luhn_validator'
5
6
  require 'active_model/validations/mod10_validator'
6
7
  require 'active_model/validations/mod11_validator'
@@ -10,3 +11,9 @@ require 'active_model/validations/cpf_or_cnpj_validator'
10
11
  require 'active_model/validations/pis_validator'
11
12
  require 'active_model/validations/titulo_eleitor_validator'
12
13
 
14
+ require 'active_record'
15
+ require 'active_record/brid_active_record'
16
+
17
+ ActiveRecord::Base.send :include, Brid::BridActiveRecord
18
+
19
+
@@ -1,5 +1,5 @@
1
1
  module Brid
2
2
  module Rails
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brid-rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Halan Pinheiro
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-07-24 00:00:00 Z
18
+ date: 2012-07-25 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activemodel
@@ -71,6 +71,7 @@ files:
71
71
  - lib/active_model/validations/mod11_validator.rb
72
72
  - lib/active_model/validations/pis_validator.rb
73
73
  - lib/active_model/validations/titulo_eleitor_validator.rb
74
+ - lib/active_record/brid_active_record.rb
74
75
  - lib/brid-rails.rb
75
76
  - lib/brid-rails/version.rb
76
77
  homepage: ""