normalizr 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/CHANGELOG.md +4 -0
- data/README.md +9 -4
- data/lib/normalizr.rb +13 -4
- data/lib/normalizr/version.rb +1 -1
- data/normalizr.gemspec +1 -1
- data/spec/lib/normalizr_spec.rb +21 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6df1b6a2804509540eacc96b2df9fd1a35ef129f64e88d672bdad2361dd92513
|
4
|
+
data.tar.gz: 46d9326603da3d5741c9174e7a579c1cc994463cdbafaeeabd13fd4bff6002d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b01d5e605d9b743a6763d68f00a14e61f70314c7f666ddc628cb1930c49acabf5faf85c2f0cccb8f5652b706f9dc6a158723e027352c792ced274338e7f946cb
|
7
|
+
data.tar.gz: 2a2501d6aca9ea1b4afdfd5b1d976b1c16cae4e285bf2f6d8cd2b143a69619d680a7b48e2c3b958810e8f057316718c91b5493d13a2fee89b1958e6202efa5e5
|
data/.travis.yml
CHANGED
@@ -9,7 +9,8 @@ gemfile:
|
|
9
9
|
- gemfiles/activerecord-6.0.x.gemfile
|
10
10
|
addons:
|
11
11
|
code_climate:
|
12
|
-
repo_token:
|
12
|
+
repo_token:
|
13
|
+
secure: Dn+nXUOFHTRUhYqYM1NYSxYSyoDhFaB2EHvlhBJ/FK3QxCy4a0beSLhs+YnDl8kI1DOrZQMl7HDrh9AHlfYvu5fX4zADD5g7JkTA2mIx1Rk3yazAUuy1j1ftX/UaowzoUAR5t0qwYm344Nnqoh+O1FujvWbiGVuZvWa6vfjFbXA=
|
13
14
|
matrix:
|
14
15
|
fast_finish: true
|
15
16
|
before_install:
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
## Normalizr
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/normalizr.svg)](https://badge.fury.io/rb/normalizr)
|
4
|
-
[![Build Status](https://travis-ci.org/
|
5
|
-
[![Code Climate](https://codeclimate.com/github/
|
6
|
-
[![Test Coverage](https://codeclimate.com/github/
|
4
|
+
[![Build Status](https://travis-ci.org/dmeremyanin/normalizr.svg?branch=master)](https://travis-ci.org/dmeremyanin/normalizr)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/dmeremyanin/normalizr/badges/gpa.svg)](https://codeclimate.com/github/dmeremyanin/normalizr)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/dmeremyanin/normalizr/badges/coverage.svg)](https://codeclimate.com/github/dmeremyanin/normalizr/coverage)
|
7
7
|
|
8
8
|
The [attribute_normalizer](https://github.com/mdeering/attribute_normalizer) replacement.
|
9
9
|
|
@@ -88,6 +88,9 @@ class User < ActiveRecord::Base
|
|
88
88
|
normalize :first_name, :last_name, :about # with default normalizers
|
89
89
|
normalize :email, with: :downcase
|
90
90
|
|
91
|
+
# you can use default and custom normalizers together
|
92
|
+
normalize :middle_name, with: [:default, :titleize]
|
93
|
+
|
91
94
|
# supports `normalize_attribute` and `normalize_attributes` as well
|
92
95
|
normalize_attribute :skype
|
93
96
|
|
@@ -95,13 +98,15 @@ class User < ActiveRecord::Base
|
|
95
98
|
normalize :skills
|
96
99
|
end
|
97
100
|
|
98
|
-
user = User.new(first_name: '', last_name: '', skills: [nil, '', ' ruby'])
|
101
|
+
user = User.new(first_name: '', last_name: '', middle_name: 'elizabeth ', skills: [nil, '', ' ruby'])
|
99
102
|
user.email = "ADDRESS@example.com"
|
100
103
|
|
101
104
|
user.first_name
|
102
105
|
#=> nil
|
103
106
|
user.last_name
|
104
107
|
#=> nil
|
108
|
+
user.middle_name
|
109
|
+
#=> "Elizabeth"
|
105
110
|
user.email
|
106
111
|
#=> "address@example.com"
|
107
112
|
user.skills
|
data/lib/normalizr.rb
CHANGED
@@ -42,12 +42,21 @@ module Normalizr
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def normalize(obj, *normalizers)
|
45
|
-
normalizers
|
46
|
-
normalizers.each do |name|
|
45
|
+
normalizers_with_default(normalizers).reduce(obj) do |memo, name|
|
47
46
|
name, options = name.first if Hash === name
|
48
|
-
|
47
|
+
|
48
|
+
process(memo, name, options)
|
49
49
|
end
|
50
|
-
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def normalizers_with_default(normalizers)
|
55
|
+
default_index = normalizers.index(:default)
|
56
|
+
|
57
|
+
normalizers[default_index.to_i] = configuration.default_normalizers if normalizers.empty? || default_index
|
58
|
+
normalizers.flatten!
|
59
|
+
normalizers
|
51
60
|
end
|
52
61
|
end
|
53
62
|
|
data/lib/normalizr/version.rb
CHANGED
data/normalizr.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ['deemox@gmail.com']
|
10
10
|
spec.description = 'Writer methods parameters normalization'
|
11
11
|
spec.summary = 'Writer methods parameters normalization'
|
12
|
-
spec.homepage = 'https://github.com/
|
12
|
+
spec.homepage = 'https://github.com/dmeremyanin/normalizr'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
|
15
15
|
spec.files = `git ls-files`.split($/)
|
data/spec/lib/normalizr_spec.rb
CHANGED
@@ -119,5 +119,26 @@ describe Normalizr do
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|
122
|
+
|
123
|
+
context 'normalizers are default and custom' do
|
124
|
+
let(:normalizers) { [:default, { truncate: { length: 8, omission: '...' }}, proc { |v| v.first(6) }] }
|
125
|
+
let(:value) { ' Lorem ipsum dolor sit amet' }
|
126
|
+
|
127
|
+
context 'string' do
|
128
|
+
let(:value) { ' Lorem ipsum dolor sit amet' }
|
129
|
+
|
130
|
+
it 'uses the default normalizers, then truncates and slices the value' do
|
131
|
+
expect(subject).to eq('Lorem.')
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'array' do
|
136
|
+
let(:value) { [' Lorem ipsum dolor sit amet', ' One more sentence', ''] }
|
137
|
+
|
138
|
+
it 'strips, truncates and then slices the value' do
|
139
|
+
expect(subject).to eq(['Lorem.', 'One m.'])
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
122
143
|
end
|
123
144
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: normalizr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -191,7 +191,7 @@ files:
|
|
191
191
|
- spec/support/models/publisher.rb
|
192
192
|
- spec/support/models/user.rb
|
193
193
|
- spec/support/schema.rb
|
194
|
-
homepage: https://github.com/
|
194
|
+
homepage: https://github.com/dmeremyanin/normalizr
|
195
195
|
licenses:
|
196
196
|
- MIT
|
197
197
|
metadata: {}
|
@@ -210,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
210
210
|
- !ruby/object:Gem::Version
|
211
211
|
version: '0'
|
212
212
|
requirements: []
|
213
|
-
rubygems_version: 3.0.
|
213
|
+
rubygems_version: 3.0.8
|
214
214
|
signing_key:
|
215
215
|
specification_version: 4
|
216
216
|
summary: Writer methods parameters normalization
|