normalizr 0.1.1 → 0.5.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 +5 -5
- data/.travis.yml +10 -8
- data/CHANGELOG.md +24 -0
- data/README.md +31 -3
- data/gemfiles/{activerecord-3.2.x.gemfile → activerecord-5.2.x.gemfile} +2 -2
- data/gemfiles/{activerecord-4.0.x.gemfile → activerecord-6.0.x.gemfile} +2 -2
- data/lib/normalizr.rb +30 -7
- data/lib/normalizr/concern.rb +10 -2
- data/lib/normalizr/configuration.rb +6 -2
- data/lib/normalizr/options_parser.rb +10 -2
- data/lib/normalizr/version.rb +1 -1
- data/normalizr.gemspec +2 -2
- data/spec/lib/normalizr/configuration_spec.rb +16 -6
- data/spec/lib/normalizr_spec.rb +96 -8
- data/spec/models/book_spec.rb +9 -6
- data/spec/models/user_spec.rb +38 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/models/book.rb +3 -0
- data/spec/support/models/user.rb +18 -0
- data/spec/support/schema.rb +3 -0
- metadata +10 -13
- data/gemfiles/activerecord-4.1.x.gemfile +0 -7
- data/gemfiles/activerecord-4.2.x.gemfile +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
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
@@ -1,16 +1,18 @@
|
|
1
1
|
language: ruby
|
2
2
|
cache: bundler
|
3
3
|
rvm:
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.
|
4
|
+
- 2.5.7
|
5
|
+
- 2.6.5
|
6
|
+
- 2.7.0
|
7
7
|
gemfile:
|
8
|
-
- gemfiles/activerecord-
|
9
|
-
- gemfiles/activerecord-
|
10
|
-
- gemfiles/activerecord-4.1.x.gemfile
|
11
|
-
- gemfiles/activerecord-4.2.x.gemfile
|
8
|
+
- gemfiles/activerecord-5.2.x.gemfile
|
9
|
+
- gemfiles/activerecord-6.0.x.gemfile
|
12
10
|
addons:
|
13
11
|
code_climate:
|
14
|
-
repo_token:
|
12
|
+
repo_token:
|
13
|
+
secure: Dn+nXUOFHTRUhYqYM1NYSxYSyoDhFaB2EHvlhBJ/FK3QxCy4a0beSLhs+YnDl8kI1DOrZQMl7HDrh9AHlfYvu5fX4zADD5g7JkTA2mIx1Rk3yazAUuy1j1ftX/UaowzoUAR5t0qwYm344Nnqoh+O1FujvWbiGVuZvWa6vfjFbXA=
|
15
14
|
matrix:
|
16
15
|
fast_finish: true
|
16
|
+
before_install:
|
17
|
+
- gem install bundler
|
18
|
+
sudo: false
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
### 0.5.0 / 2020-07-27
|
2
|
+
|
3
|
+
* Add ability to use default and custom normalizers together (@subbbotin)
|
4
|
+
|
5
|
+
### 0.4.0 / 2020-01-20
|
6
|
+
|
7
|
+
* Support Ruby 2.7 (@badlamer)
|
8
|
+
|
9
|
+
### 0.3.1 / 2018-03-22
|
10
|
+
|
11
|
+
* Fix conditional normalization
|
12
|
+
|
13
|
+
### 0.3.0 / 2018-03-21
|
14
|
+
|
15
|
+
* Add a possibility to use if/unless cases for normalizer options (@TheTharin)
|
16
|
+
|
17
|
+
### 0.2.0 / 2016-03-17
|
18
|
+
|
19
|
+
* Introduce arrays normalization
|
20
|
+
|
21
|
+
### 0.1.1 / 2015-11-12
|
22
|
+
|
23
|
+
* New `parameterize` normalizer
|
24
|
+
|
1
25
|
### 0.1.0 / 2014-08-30
|
2
26
|
|
3
27
|
* Add Mongoid integration
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
## Normalizr
|
2
2
|
|
3
|
-
[](https://badge.fury.io/rb/normalizr)
|
4
|
+
[](https://travis-ci.org/dmeremyanin/normalizr)
|
5
|
+
[](https://codeclimate.com/github/dmeremyanin/normalizr)
|
6
|
+
[](https://codeclimate.com/github/dmeremyanin/normalizr/coverage)
|
4
7
|
|
5
8
|
The [attribute_normalizer](https://github.com/mdeering/attribute_normalizer) replacement.
|
6
9
|
|
@@ -71,7 +74,7 @@ Normalizr.configure do
|
|
71
74
|
add :indent do |value, amount = 2|
|
72
75
|
if String === value
|
73
76
|
value.indent(amount)
|
74
|
-
|
77
|
+
else
|
75
78
|
value
|
76
79
|
end
|
77
80
|
end
|
@@ -85,19 +88,29 @@ class User < ActiveRecord::Base
|
|
85
88
|
normalize :first_name, :last_name, :about # with default normalizers
|
86
89
|
normalize :email, with: :downcase
|
87
90
|
|
91
|
+
# you can use default and custom normalizers together
|
92
|
+
normalize :middle_name, with: [:default, :titleize]
|
93
|
+
|
88
94
|
# supports `normalize_attribute` and `normalize_attributes` as well
|
89
95
|
normalize_attribute :skype
|
96
|
+
|
97
|
+
# array normalization is supported too
|
98
|
+
normalize :skills
|
90
99
|
end
|
91
100
|
|
92
|
-
user = User.new(first_name: '', last_name: '')
|
101
|
+
user = User.new(first_name: '', last_name: '', middle_name: 'elizabeth ', skills: [nil, '', ' ruby'])
|
93
102
|
user.email = "ADDRESS@example.com"
|
94
103
|
|
95
104
|
user.first_name
|
96
105
|
#=> nil
|
97
106
|
user.last_name
|
98
107
|
#=> nil
|
108
|
+
user.middle_name
|
109
|
+
#=> "Elizabeth"
|
99
110
|
user.email
|
100
111
|
#=> "address@example.com"
|
112
|
+
user.skills
|
113
|
+
#=> ["ruby"]
|
101
114
|
```
|
102
115
|
|
103
116
|
```ruby
|
@@ -122,6 +135,21 @@ sms.message
|
|
122
135
|
#=> "It works"
|
123
136
|
```
|
124
137
|
|
138
|
+
You can also use if/unless options (they accept a symbol (method name) or proc):
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
class Book
|
142
|
+
include Normalizr::Concerns
|
143
|
+
|
144
|
+
attr_accessor :author, :description, :date
|
145
|
+
|
146
|
+
normalize :author, if: :author_should_be_normalized?
|
147
|
+
normalize :description, unless: :description_should_not_be_normalized?
|
148
|
+
|
149
|
+
normalize :author, if: -> { date.today? }
|
150
|
+
end
|
151
|
+
```
|
152
|
+
|
125
153
|
Normalize values outside of class:
|
126
154
|
|
127
155
|
```ruby
|
data/lib/normalizr.rb
CHANGED
@@ -15,8 +15,12 @@ module Normalizr
|
|
15
15
|
@configuration ||= Configuration.new
|
16
16
|
end
|
17
17
|
|
18
|
-
def configure
|
19
|
-
|
18
|
+
def configure(&block)
|
19
|
+
unless block_given?
|
20
|
+
raise ArgumentError, '.configure must be called with a block'
|
21
|
+
end
|
22
|
+
|
23
|
+
configuration.instance_eval(&block)
|
20
24
|
end
|
21
25
|
|
22
26
|
def find(name)
|
@@ -27,13 +31,32 @@ module Normalizr
|
|
27
31
|
end
|
28
32
|
end
|
29
33
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
34
|
+
def process(obj, name, options)
|
35
|
+
if Array === obj
|
36
|
+
obj.map { |item| process(item, name, options) }.tap do |ary|
|
37
|
+
ary.compact! if name == :blank
|
38
|
+
end
|
39
|
+
else
|
40
|
+
find(name).call(obj, options)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def normalize(obj, *normalizers)
|
45
|
+
normalizers_with_default(normalizers).reduce(obj) do |memo, name|
|
33
46
|
name, options = name.first if Hash === name
|
34
|
-
|
47
|
+
|
48
|
+
process(memo, name, options)
|
35
49
|
end
|
36
|
-
|
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
|
37
60
|
end
|
38
61
|
end
|
39
62
|
|
data/lib/normalizr/concern.rb
CHANGED
@@ -11,8 +11,16 @@ module Normalizr
|
|
11
11
|
prepend Module.new {
|
12
12
|
options.attributes.each do |method|
|
13
13
|
define_method :"#{method}=" do |value|
|
14
|
-
|
15
|
-
|
14
|
+
condition_lambda = -> condition { Proc === condition ? instance_exec(&condition) : send(condition) }
|
15
|
+
|
16
|
+
positive = options.positive_condition.all?(&condition_lambda)
|
17
|
+
negative = options.negative_condition.none?(&condition_lambda)
|
18
|
+
|
19
|
+
if positive && negative
|
20
|
+
value = Normalizr.normalize(value, *options.before)
|
21
|
+
value = Normalizr.normalize(value, *options.after) if options.after.any?
|
22
|
+
end
|
23
|
+
|
16
24
|
super(value)
|
17
25
|
end
|
18
26
|
end
|
@@ -14,8 +14,12 @@ module Normalizr
|
|
14
14
|
self.default_normalizers = normalizers
|
15
15
|
end
|
16
16
|
|
17
|
-
def add(name)
|
18
|
-
|
17
|
+
def add(name, &block)
|
18
|
+
unless block_given?
|
19
|
+
raise ArgumentError, '#add must be called with a block'
|
20
|
+
end
|
21
|
+
|
22
|
+
normalizers[name] = block
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
@@ -8,14 +8,22 @@ module Normalizr
|
|
8
8
|
@block = block
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def before
|
12
12
|
options_at(:with, :before) { block }
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def after
|
16
16
|
options_at(:after)
|
17
17
|
end
|
18
18
|
|
19
|
+
def positive_condition
|
20
|
+
options_at(:if)
|
21
|
+
end
|
22
|
+
|
23
|
+
def negative_condition
|
24
|
+
options_at(:unless)
|
25
|
+
end
|
26
|
+
|
19
27
|
private
|
20
28
|
|
21
29
|
def options_at(*keys)
|
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($/)
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.required_ruby_version = '>= 2.0'
|
20
20
|
|
21
21
|
spec.add_development_dependency 'pry'
|
22
|
-
spec.add_development_dependency 'bundler'
|
22
|
+
spec.add_development_dependency 'bundler'
|
23
23
|
spec.add_development_dependency 'rake'
|
24
24
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
25
|
spec.add_development_dependency 'rspec-its'
|
@@ -5,17 +5,27 @@ describe Normalizr::Configuration do
|
|
5
5
|
subject { configuration }
|
6
6
|
|
7
7
|
describe '#default' do
|
8
|
-
|
9
|
-
|
8
|
+
it 'accpets default normalizers' do
|
9
|
+
subject.default(:blank)
|
10
|
+
expect(subject.default_normalizers).to eq([:blank])
|
11
|
+
end
|
10
12
|
end
|
11
13
|
|
12
14
|
describe '#normalizer_names' do
|
13
|
-
|
14
|
-
|
15
|
+
it 'returns normalized names' do
|
16
|
+
allow(subject).to receive(:normalizers) {{ blank: proc {}}}
|
17
|
+
expect(subject.normalizer_names).to eq([:blank])
|
18
|
+
end
|
15
19
|
end
|
16
20
|
|
17
21
|
describe '#add' do
|
18
|
-
|
19
|
-
|
22
|
+
it 'requires block' do
|
23
|
+
expect { subject.add(:blank) }.to raise_error(ArgumentError)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'accepts block' do
|
27
|
+
subject.add(:blank) {}
|
28
|
+
expect(subject.normalizer_names).to include(:blank)
|
29
|
+
end
|
20
30
|
end
|
21
31
|
end
|
data/spec/lib/normalizr_spec.rb
CHANGED
@@ -17,7 +17,7 @@ describe Normalizr do
|
|
17
17
|
context 'not existed normalizer' do
|
18
18
|
let(:normalizer) { :not_existed }
|
19
19
|
|
20
|
-
it '
|
20
|
+
it 'raises the exception with normalizer in message' do
|
21
21
|
expect { subject }.to raise_error(Normalizr::MissingNormalizer, /not_existed/)
|
22
22
|
end
|
23
23
|
end
|
@@ -31,25 +31,113 @@ describe Normalizr do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
describe '#process' do
|
35
|
+
subject { described_class.process(obj, name, {}) }
|
36
|
+
|
37
|
+
context 'string' do
|
38
|
+
let(:obj) { ' test ' }
|
39
|
+
|
40
|
+
context 'blank normalizer' do
|
41
|
+
let(:name) { :strip }
|
42
|
+
|
43
|
+
it 'strips the value' do
|
44
|
+
should == 'test'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'array ' do
|
50
|
+
let(:obj) { [nil, ' '] }
|
51
|
+
|
52
|
+
context 'strip normalizer' do
|
53
|
+
let(:name) { :strip }
|
54
|
+
|
55
|
+
it 'strips all elements' do
|
56
|
+
expect(subject).to eq([nil, ''])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'custom normalizer' do
|
61
|
+
let(:name) { proc { |value| value.prepend('N:') if String === value }}
|
62
|
+
|
63
|
+
it 'processes all elements with the custom normalizer' do
|
64
|
+
expect(subject).to eq([nil, 'N: '])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'blank normalizer' do
|
69
|
+
let(:name) { :blank }
|
70
|
+
|
71
|
+
it 'returns empty array' do
|
72
|
+
expect(subject).to eq([])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
34
78
|
describe '#normalize' do
|
35
79
|
before { configuration.default_normalizers = [:strip, :blank] }
|
36
80
|
subject { described_class.normalize(value, *normalizers) }
|
37
81
|
|
38
|
-
|
82
|
+
|
83
|
+
context 'normalizers are empty' do
|
39
84
|
let(:normalizers) { [] }
|
40
|
-
let(:value) { ' text ' }
|
41
85
|
|
42
|
-
|
43
|
-
|
86
|
+
context 'string' do
|
87
|
+
let(:value) { ' text ' }
|
88
|
+
|
89
|
+
it 'uses the default normalizers' do
|
90
|
+
expect(subject).to eq('text')
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'array' do
|
95
|
+
let(:value) { [nil, ' test '] }
|
96
|
+
|
97
|
+
it 'uses the default normalizers' do
|
98
|
+
expect(subject).to eq(['test'])
|
99
|
+
end
|
44
100
|
end
|
45
101
|
end
|
46
102
|
|
47
|
-
context 'normalizers
|
103
|
+
context 'normalizers are not empty' do
|
48
104
|
let(:normalizers) { [:strip, { truncate: { length: 8, omission: '...' }}, proc { |v| v.first(6) }] }
|
105
|
+
|
106
|
+
context 'string' do
|
107
|
+
let(:value) { ' Lorem ipsum dolor sit amet' }
|
108
|
+
|
109
|
+
it 'strips, truncates and then slices the value' do
|
110
|
+
expect(subject).to eq('Lorem.')
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'array' do
|
115
|
+
let(:value) { [' Lorem ipsum dolor sit amet', ' One more sentence'] }
|
116
|
+
|
117
|
+
it 'strips, truncates and then slices the value' do
|
118
|
+
expect(subject).to eq(['Lorem.', 'One m.'])
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'normalizers are default and custom' do
|
124
|
+
let(:normalizers) { [:default, { truncate: { length: 8, omission: '...' }}, proc { |v| v.first(6) }] }
|
49
125
|
let(:value) { ' Lorem ipsum dolor sit amet' }
|
50
126
|
|
51
|
-
|
52
|
-
|
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
|
53
141
|
end
|
54
142
|
end
|
55
143
|
end
|
data/spec/models/book_spec.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Book do
|
4
|
-
it { should
|
5
|
-
it { should
|
6
|
-
it { should
|
7
|
-
it { should
|
4
|
+
it { should normalize(:author).from(' Michael Deering ').to('Michael Deering') }
|
5
|
+
it { should normalize(:us_price).from('$3.50').to(3.50) }
|
6
|
+
it { should normalize(:cnd_price).from('$3,450.98').to(3450.98) }
|
7
|
+
it { should normalize(:summary).from(' Here is my summary that is a little to long ').to('Here is m...') }
|
8
|
+
it { should normalize(:title).from('pick up chicks with magic tricks').to('Pick Up Chicks With Magic Tricks') }
|
8
9
|
|
9
|
-
it { should
|
10
|
+
it { should normalize(:tags).from(['', nil, ' ', ' test']).to(['test']) }
|
11
|
+
it { should normalize(:tags).from([[''], [nil, ' test ']]).to([[], ['test']]) } # nested arrays
|
12
|
+
it { should normalize(:tags).from([]).to([]) }
|
10
13
|
|
11
14
|
context 'normalization should not interfere with other hooks and aliases on the attribute assignment' do
|
12
15
|
before do
|
@@ -22,7 +25,7 @@ describe Book do
|
|
22
25
|
before do
|
23
26
|
@book = Book.create!(title: 'Original Title')
|
24
27
|
@book2 = Book.find(@book.id)
|
25
|
-
@book2.
|
28
|
+
@book2.update(title: 'New Title')
|
26
29
|
end
|
27
30
|
|
28
31
|
it "should reflect the change when the record is reloaded" do
|
data/spec/models/user_spec.rb
CHANGED
@@ -4,4 +4,42 @@ describe User do
|
|
4
4
|
context 'on default attribute with the default normalizer changed' do
|
5
5
|
it { should normalize_attribute(:firstname).from(' here ').to('here') }
|
6
6
|
end
|
7
|
+
|
8
|
+
context 'last name has to be normalized' do
|
9
|
+
before do
|
10
|
+
allow(subject).to receive(:should_normalize_lastname?).and_return(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
it { is_expected.to normalize_attribute(:lastname).from(' here ').to('here') }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'last name cannot be normalized' do
|
17
|
+
before do
|
18
|
+
allow(subject).to receive(:should_normalize_lastname?).and_return(false)
|
19
|
+
end
|
20
|
+
|
21
|
+
it { is_expected.not_to normalize_attribute(:lastname).from(' here ').to('here') }
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'maidenname has to be normalized' do
|
25
|
+
before do
|
26
|
+
allow(subject).to receive(:should_normalize_maidenname_positive?).and_return(true)
|
27
|
+
allow(subject).to receive(:should_normalize_maidenname_negative?).and_return(false)
|
28
|
+
end
|
29
|
+
|
30
|
+
it { is_expected.to normalize_attribute(:maidenname).from(' boba ').to('boba') }
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'maidenname cannot to be normalized' do
|
34
|
+
before do
|
35
|
+
allow(subject).to receive(:should_normalize_maidenname_positive?).and_return(true)
|
36
|
+
allow(subject).to receive(:should_normalize_maidenname_negative?).and_return(true)
|
37
|
+
end
|
38
|
+
|
39
|
+
it { is_expected.not_to normalize_attribute(:maidenname).from(' boba ').to('boba') }
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'favouritebook has to be normalized with proc' do
|
43
|
+
it { is_expected.to normalize_attribute(:favouritebook).from(' Евангелие от Матфея ').to('Евангелие от Матфея') }
|
44
|
+
end
|
7
45
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/models/book.rb
CHANGED
data/spec/support/models/user.rb
CHANGED
@@ -1,3 +1,21 @@
|
|
1
1
|
class User < Person
|
2
2
|
normalize_attribute :firstname
|
3
|
+
|
4
|
+
normalize :lastname, if: :should_normalize_lastname?
|
5
|
+
normalize :maidenname, if: :should_normalize_maidenname_positive?, unless: :should_normalize_maidenname_negative?
|
6
|
+
normalize :favouritebook, if: -> { true }
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def should_normalize_lastname?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
def should_normalize_maidenname_positive?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def should_normalize_maidenname_negative?
|
19
|
+
false
|
20
|
+
end
|
3
21
|
end
|
data/spec/support/schema.rb
CHANGED
@@ -22,6 +22,7 @@ ActiveRecord::Schema.define do
|
|
22
22
|
t.decimal :us_price
|
23
23
|
t.string :summary
|
24
24
|
t.string :title
|
25
|
+
t.text :tags
|
25
26
|
end
|
26
27
|
|
27
28
|
create_table :journals, force: true do |t|
|
@@ -37,5 +38,7 @@ ActiveRecord::Schema.define do
|
|
37
38
|
create_table :users, force: true do |t|
|
38
39
|
t.string :firstname
|
39
40
|
t.string :lastname
|
41
|
+
t.string :maidenname
|
42
|
+
t.string :favouritebook
|
40
43
|
end
|
41
44
|
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:
|
11
|
+
date: 2020-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -151,10 +151,8 @@ files:
|
|
151
151
|
- LICENSE.txt
|
152
152
|
- README.md
|
153
153
|
- Rakefile
|
154
|
-
- gemfiles/activerecord-
|
155
|
-
- gemfiles/activerecord-
|
156
|
-
- gemfiles/activerecord-4.1.x.gemfile
|
157
|
-
- gemfiles/activerecord-4.2.x.gemfile
|
154
|
+
- gemfiles/activerecord-5.2.x.gemfile
|
155
|
+
- gemfiles/activerecord-6.0.x.gemfile
|
158
156
|
- lib/normalizr.rb
|
159
157
|
- lib/normalizr/concern.rb
|
160
158
|
- lib/normalizr/configuration.rb
|
@@ -193,7 +191,7 @@ files:
|
|
193
191
|
- spec/support/models/publisher.rb
|
194
192
|
- spec/support/models/user.rb
|
195
193
|
- spec/support/schema.rb
|
196
|
-
homepage: https://github.com/
|
194
|
+
homepage: https://github.com/dmeremyanin/normalizr
|
197
195
|
licenses:
|
198
196
|
- MIT
|
199
197
|
metadata: {}
|
@@ -212,8 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
210
|
- !ruby/object:Gem::Version
|
213
211
|
version: '0'
|
214
212
|
requirements: []
|
215
|
-
|
216
|
-
rubygems_version: 2.4.8
|
213
|
+
rubygems_version: 3.0.8
|
217
214
|
signing_key:
|
218
215
|
specification_version: 4
|
219
216
|
summary: Writer methods parameters normalization
|