serializers 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7561422cad0b5927baeeaed13d36fd72dd2e0da02da891be308859c4b9627c8e
4
+ data.tar.gz: 78135d5e60f187a4a27229a4f5da1d3d0ce08be0903d839ee232ea27bc234b96
5
+ SHA512:
6
+ metadata.gz: 71fc1a300549d83efb9251f346c12bf2bb0ca71af600b2f98e0dec1e655772772b6b9715407abeecfdcb718aa5119e236c3804b158aaa484ca0e98a4588739c4
7
+ data.tar.gz: d0cdc7e7f598f723f552a8e73d111f3f0d62bfc69a5641e201b671e16707315d0e5c4902a1f201d41a758c2a0c5db6c1b9877b00b9f7d693ee21ba1488eacf7a
@@ -0,0 +1,43 @@
1
+ # Serializers
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/serializers`. 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
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'serializers'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install serializers
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/serializers. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Serializers project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/serializers/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "serializers/version"
2
+
3
+ require "serializers/activerecord"
4
+
5
+ module Serializers
6
+ end
@@ -0,0 +1,9 @@
1
+ require "serializers/activerecord/br/cnpj"
2
+ require "serializers/activerecord/br/cpf"
3
+
4
+ require "serializers/activerecord/email"
5
+
6
+ module Serializers
7
+ module Activerecord
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ require "cpf_cnpj"
2
+
3
+ module Serializers
4
+ module Activerecord
5
+ module BR
6
+ class CNPJ
7
+ def self.dump(cnpj)
8
+ cnpj = ::CNPJ.new(cnpj)
9
+ cnpj.stripped
10
+ end
11
+
12
+ def self.load(cnpj)
13
+ cnpj = ::CNPJ.new(cnpj)
14
+ cnpj.formatted
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "cpf_cnpj"
2
+
3
+ module Serializers
4
+ module Activerecord
5
+ module BR
6
+ class CPF
7
+ def self.dump(cpf)
8
+ cpf = ::CPF.new(cpf)
9
+ cpf.stripped
10
+ end
11
+
12
+ def self.load(cpf)
13
+ cpf = ::CPF.new(cpf)
14
+ cpf.formatted
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module Serializers
2
+ module Activerecord
3
+ class Email
4
+ def self.dump(email)
5
+ email.downcase
6
+ end
7
+
8
+ def self.load(email)
9
+ email
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Serializers
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,19 @@
1
+ require "support/spec_helper"
2
+
3
+ describe Serializers::Activerecord::BR::CNPJ, type: :activerecord do
4
+ let(:serializer) { described_class }
5
+
6
+ describe '#dump' do
7
+ it 'dump CNPJ without format' do
8
+ dumped = serializer.dump('01.234.567/0001-89')
9
+ expect(dumped).to eq('01234567000189')
10
+ end
11
+ end
12
+
13
+ describe '#load' do
14
+ it 'load CNPJ formatted' do
15
+ loaded = serializer.load('01234567000189')
16
+ expect(loaded).to eq('01.234.567/0001-89')
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "support/spec_helper"
2
+
3
+ describe Serializers::Activerecord::BR::CPF, type: :activerecord do
4
+ let(:serializer) { described_class }
5
+
6
+ describe '#dump' do
7
+ it 'dump CPF without format' do
8
+ dumped = serializer.dump('012.345.678-90')
9
+ expect(dumped).to eq('01234567890')
10
+ end
11
+ end
12
+
13
+ describe '#load' do
14
+ it 'load CPF formatted' do
15
+ loaded = serializer.load('01234567890')
16
+ expect(loaded).to eq('012.345.678-90')
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "support/spec_helper"
2
+
3
+ describe Serializers::Activerecord::Email, type: :activerecord do
4
+ let(:serializer) { described_class }
5
+
6
+ describe '#dump' do
7
+ it 'dump email as lowercase' do
8
+ dumped = serializer.dump('EMAIL@email.cOm')
9
+ expect(dumped).to eq('email@email.com')
10
+ end
11
+ end
12
+
13
+ describe '#load' do
14
+ it 'load email as it was saved' do
15
+ loaded = serializer.load('Email@email.com')
16
+ expect(loaded).to eq('Email@email.com')
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ RSpec.describe Serializers do
2
+ it "has a version number" do
3
+ expect(Serializers::VERSION).not_to be nil
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require "bundler/setup"
2
+ require "serializers"
3
+
4
+ require "rspec/collection_matchers"
5
+
6
+ RSpec.configure do |config|
7
+ config.run_all_when_everything_filtered = true
8
+ config.order = 'random'
9
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: serializers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Reinaldo Oliveira (k1ng)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cpf_cnpj
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-meta
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-collection_matchers
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ description: Basic serializers
84
+ email:
85
+ - reinaldooli@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - README.md
91
+ - lib/serializers.rb
92
+ - lib/serializers/activerecord.rb
93
+ - lib/serializers/activerecord/br/cnpj.rb
94
+ - lib/serializers/activerecord/br/cpf.rb
95
+ - lib/serializers/activerecord/email.rb
96
+ - lib/serializers/version.rb
97
+ - spec/activerecord/br/cnpj_spec.rb
98
+ - spec/activerecord/br/cpf_spec.rb
99
+ - spec/activerecord/email_spec.rb
100
+ - spec/serializers_spec.rb
101
+ - spec/support/spec_helper.rb
102
+ homepage: https://github.com/reinaldooli/serializers
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.7.7
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Some serializers for Ruby/Rails
126
+ test_files:
127
+ - spec/serializers_spec.rb
128
+ - spec/activerecord/br/cpf_spec.rb
129
+ - spec/activerecord/br/cnpj_spec.rb
130
+ - spec/activerecord/email_spec.rb
131
+ - spec/support/spec_helper.rb