normalizr 0.3.1 → 0.4.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 +5 -8
- data/CHANGELOG.md +4 -0
- 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 +6 -2
- data/lib/normalizr/concern.rb +2 -2
- data/lib/normalizr/configuration.rb +6 -2
- data/lib/normalizr/version.rb +1 -1
- data/normalizr.gemspec +1 -1
- data/spec/lib/normalizr/configuration_spec.rb +16 -6
- data/spec/models/book_spec.rb +1 -1
- metadata +9 -12
- 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
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d46a399a42b6686eb841774af8c65fe00a01440b8b987babae87b43c8f3ea557
|
4
|
+
data.tar.gz: cae7060a66923fe7a5f208d7e7b5649d3d49c1c02780361c88400eef3f451ae7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89c5535023a0c3119f959f782c112eb70c1525ba7dc3e82eb45bad8d9702b393df73683af9a3ca5f1d1a085a4888f80a9c0142eb3def7f3c0c76ea9def169895
|
7
|
+
data.tar.gz: e6a67050e0f4d1761db25b0fd72cbaf4b4f241489016a3076cfcb5768cf8290cf9f69af2e774aa575d8ee25b07397eecd4ad843fc35e133293508732ab864bd6
|
data/.travis.yml
CHANGED
@@ -1,15 +1,12 @@
|
|
1
1
|
language: ruby
|
2
2
|
cache: bundler
|
3
3
|
rvm:
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
- 2.3.0
|
4
|
+
- 2.5.7
|
5
|
+
- 2.6.5
|
6
|
+
- 2.7.0
|
8
7
|
gemfile:
|
9
|
-
- gemfiles/activerecord-
|
10
|
-
- gemfiles/activerecord-
|
11
|
-
- gemfiles/activerecord-4.1.x.gemfile
|
12
|
-
- gemfiles/activerecord-4.2.x.gemfile
|
8
|
+
- gemfiles/activerecord-5.2.x.gemfile
|
9
|
+
- gemfiles/activerecord-6.0.x.gemfile
|
13
10
|
addons:
|
14
11
|
code_climate:
|
15
12
|
repo_token: 1cac54041089115a5bf218169b62c76c8b87a5896f5aa973f89637a8553c0376
|
data/CHANGELOG.md
CHANGED
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)
|
data/lib/normalizr/concern.rb
CHANGED
@@ -13,8 +13,8 @@ module Normalizr
|
|
13
13
|
define_method :"#{method}=" do |value|
|
14
14
|
condition_lambda = -> condition { Proc === condition ? instance_exec(&condition) : send(condition) }
|
15
15
|
|
16
|
-
positive = options.positive_condition.all?
|
17
|
-
negative = options.negative_condition.none?
|
16
|
+
positive = options.positive_condition.all?(&condition_lambda)
|
17
|
+
negative = options.negative_condition.none?(&condition_lambda)
|
18
18
|
|
19
19
|
if positive && negative
|
20
20
|
value = Normalizr.normalize(value, *options.before)
|
@@ -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
|
data/lib/normalizr/version.rb
CHANGED
data/normalizr.gemspec
CHANGED
@@ -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/models/book_spec.rb
CHANGED
@@ -25,7 +25,7 @@ describe Book do
|
|
25
25
|
before do
|
26
26
|
@book = Book.create!(title: 'Original Title')
|
27
27
|
@book2 = Book.find(@book.id)
|
28
|
-
@book2.
|
28
|
+
@book2.update(title: 'New Title')
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should reflect the change when the record is reloaded" do
|
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.4.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-01-20 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
|
@@ -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.7.6
|
213
|
+
rubygems_version: 3.0.3
|
217
214
|
signing_key:
|
218
215
|
specification_version: 4
|
219
216
|
summary: Writer methods parameters normalization
|